草庐IT

GetValueOrDefault

全部标签

c# - LINQ to Entities 无法识别方法 'System.DateTime GetValueOrDefault()'

努力使用非常简单的代码,这些代码在其他类中可以使用类似代码的地方不起作用。如果我删除GetValueOrDefault(),它将无法编译。我也在使用System.Linq。我收到此运行时错误:LINQtoEntities无法识别方法“System.DateTimeGetValueOrDefault()”。有任何想法吗?publicListGetAll(stringcustomer_number){addresses=(fromaindb.ADDRESSwherea.CUSTOMER_NUMBER.Equals(customer_number)selectnewAddressModel{

c# - LINQ to Entities 无法识别方法 'System.DateTime GetValueOrDefault()'

努力使用非常简单的代码,这些代码在其他类中可以使用类似代码的地方不起作用。如果我删除GetValueOrDefault(),它将无法编译。我也在使用System.Linq。我收到此运行时错误:LINQtoEntities无法识别方法“System.DateTimeGetValueOrDefault()”。有任何想法吗?publicListGetAll(stringcustomer_number){addresses=(fromaindb.ADDRESSwherea.CUSTOMER_NUMBER.Equals(customer_number)selectnewAddressModel{

c# - GetValueOrDefault 是如何工作的?

我负责LINQ提供程序,该提供程序对C#代码执行一些运行时评估。例如:int?thing=null;accessor.Product.Where(p=>p.anInt==thing.GetValueOrDefault(-1))目前,由于thing为空,上述代码不适用于我的LINQ提供程序。虽然我已经使用C#很长时间了,但我不知道GetValueOrDefault是如何实现的,因此我应该如何解决这个问题。所以我的问题是:GetValueOrDefault在调用它的实例为空的情况下如何工作?为什么不抛出NullReferenceException?后续问题:鉴于我需要处理空值,我应该如何使