[英]Returning value on null linq query
Hi I have following linq query嗨,我有以下 linq 查询
var query=DbContext.Set<tasksList>()
Select(u=> new { tasks= u.description});
What I want to do is as it iterates through if description is null to return some other value for example return just 1 or anything.我想要做的是,如果 description 为空,它会迭代返回一些其他值,例如只返回 1 或任何值。 Please let me know how to achieve this Thanks
请让我知道如何实现这一点谢谢
You could use the null coalescing operator.您可以使用空合并运算符。
var query = DbContext.Set<tasksList>()
.Select(u=> new { tasks= u.description ?? "just 1 or anything"});
Example : Code Project - How to Use Null-Coalescing Operator (??)示例: 代码项目 - 如何使用空合并运算符 (??)
Reference : Reference MSDN参考:参考 MSDN
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.