请问关于c的具体应用场景有哪些?
- 内容介绍
- 文章标签
- 相关推荐
本文共计168个文字,预计阅读时间需要1分钟。
简单的LINQ查询如下:csharpfrom transport in db.Transportsselect new { Current=transport.CurrentLocation, CurrentCarriers=transport.CurrentLocation==null ? null : transport.CurrentLocation.Carriers};
简单的LINQ查询:from transport in db.Transports select new { Current = transport.CurrentLocation, CurrentCarriers = transport.CurrentLocation.Carriers, };
问题:CurrentLocation可能为null.如果是,则执行此查询会抛出NullReference.我尝试添加支票
transport.CurrentLocation == null ? null : transport.CurrentLocation.Carriers
但Linq to sql似乎无法解析那个.
任何不错的解决方案,不涉及为每个传输发送额外的查询?
我通常只是使用’let’.from x in Foo let y = x.Bar where y != null select y.Baz;
更新:
我觉得 ??运算符确实转换为SQL.
本文共计168个文字,预计阅读时间需要1分钟。
简单的LINQ查询如下:csharpfrom transport in db.Transportsselect new { Current=transport.CurrentLocation, CurrentCarriers=transport.CurrentLocation==null ? null : transport.CurrentLocation.Carriers};
简单的LINQ查询:from transport in db.Transports select new { Current = transport.CurrentLocation, CurrentCarriers = transport.CurrentLocation.Carriers, };
问题:CurrentLocation可能为null.如果是,则执行此查询会抛出NullReference.我尝试添加支票
transport.CurrentLocation == null ? null : transport.CurrentLocation.Carriers
但Linq to sql似乎无法解析那个.
任何不错的解决方案,不涉及为每个传输发送额外的查询?
我通常只是使用’let’.from x in Foo let y = x.Bar where y != null select y.Baz;
更新:
我觉得 ??运算符确实转换为SQL.

