Here is what I want to do : Get a List of Batch Objects in my controller that I can send to the view and display it. It's working but the values are mixed up. If the value in the database is null or 0, the query fills it with another non-null value in the record. Here's an example.
Database Content
Id:13
TotalRequest : 10
TotalProcessed :0
CreatedDateTime:2017-01-13 13:30:46.090
CreatedBy:Test
CompletionDateTime : NULL
Iqueryable at position 13 content
Id:13
TotalRequest : 10
TotalProcessed :10
CreatedDateTime:2017-01-13 13:30:46.090
CreatedBy:Test
CompletionDateTime : NULL
You can see that the TotalProcessed is not correct. Also if I have a CompletionDateTime that is not null in one of the objects, the List doesn't care and always outputs null
The code:
IQueryable<Batch> IBatchList = context.batch.OrderByDescending(b => b.CreatedDateTime);
var batchList = IBatchList.ToList();
Batch Class(code first DB, so it's the definition of the DB as well)
public class Batch
{
[Key]
public Int64 Id { get; set; }
public int TotalRequested { get; set; }
public int TotalProcessed { get; set; }
public DateTime CreatedDateTime { get; set; }
public string CreatedBy { get; set; }
public DateTime? CompletedDateTime { get; set; }
}
Id TotalRequested TotalProcessed CreatedDateTime CreatedBy CompletedDateTime
13 10 0 2017-01-13 13:30:46.090 Test NULL
Here's the query from the Iqueryable :
{SELECT
[Extent1].[Id] AS [Id],
[Extent1].[TotalRequested] AS [TotalRequested],
[Extent1].[TotalProcessed] AS [TotalProcessed],
[Extent1].[CreatedDateTime] AS [CreatedDateTime],
[Extent1].[CreatedBy] AS [CreatedBy],
[Extent1].[CompletedDateTime] AS [CompletedDateTime]
FROM [dbo].[Batch] AS [Extent1]
ORDER BY [Extent1].[CreatedDateTime] DESC}