Csharp/C#教程:entity framework5.0。 我的查询有什么问题?分享


entity framework5.0。 我的查询有什么问题?

这是我的代码:

public DateTime GibSomeStartDate(IEnumerable partnerNumbers, DateTime startTime) { var contractsStartDate = from contract in this.databaseContext.Contract where partnerNumbers.Contains(contract.Pnr) && contract.SomeDateTime >= startTime select contract.SomeDateTime; } 

如果我调用contractsStartDate.Min() ,则会发生exception:

 Unable to create a null constant value of type 'System.Collections.Generic.IEnumerable`1'. Only entity types, enumeration types or primitive types are supported in this context. 

我的查询有什么问题?

我知道这个错误。 只需确保partnerNumbers不为null。 您为此参数传递了null值,但Linq-to-entities无法将该值转换为任何有意义的值。

 if (partnerNumbers == null) { throw new ArgumentNullException("partnerNumbers"); } 

额外的奖励建议:

如果SomeDateTime not nullable并且枚举中没有条目,那么在调用Min()会出现exception。 将SomeDateTime转换为查询中的nullable类型将起作用,然后在没有条目时SomeDateTime null。

上述就是C#学习教程:entity framework5.0。 我的查询有什么问题?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/985624.html

(0)
上一篇 2021年12月21日
下一篇 2021年12月21日

精彩推荐