这就是我想要做的:在我的控制器中获取一个批处理对象列表,我可以将其发送到视图并显示它。它正在运作,但价值观混杂在一起。如果数据库中的值为null或0,则查询将使用记录中的另一个非null值填充它。这是一个例子。
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
您可以看到TotalProcessed不正确。此外,如果我在其中一个对象中有一个非空的CompletionDateTime,那么List并不关心并始终输出null
代码:
IQueryable<Batch> IBatchList = context.batch.OrderByDescending(b => b.CreatedDateTime);
var batchList = IBatchList.ToList();
批次类(代码第一个DB,所以它也是数据库的定义)
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
这是来自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}
答案 0 :(得分:0)
我解决了这个问题,我不知道为什么要修复它,但我在查询中添加了一个where语句(顺便说一句,CreatedDateTime永远不会为null,所以我总是会返回所有记录)现在我掌握了所有正确的数据。
\layout