I'm developing a web service in .NET (C#) which shows in a XML the results of a SQL query. The query is:
return dbContext.data
.SqlQuery("SELECT a, b, c, d, e, f, g FROM person").ToList();
Let's say now that fields f and g are null in my database. In my web service I get this:
<person>
<a>'LU'</a>
<b>'1'</b>
<c>'JOHN'</c>
<d>'1'</d>
<e>'REP1'</e>
</person>
As you can see, fields f and g are not showing in the XML result. Since I'm inserting this data into an SQLite database I would like to get ALSO the empty/null fields, so the database structure still the same. I would like something like that:
<person>
<a>'LU'</a>
<b>'1'</b>
<c>'JOHN'</c>
<d>'1'</d>
<e>'REP1'</e>
<f></f>
<g></g>
</person>
Before posting here, I've tried using ISNULL in my SQL query:
return dbContext.data
.SqlQuery("SELECT a, b, c, d, e, ISNULL(f, null) as f, ISNULL(g,null) as g FROM person").ToList();
But it's not working. Any idea of how can I get all the fields in the XML even when they are empty or null?
Aucun commentaire:
Enregistrer un commentaire