[英]linq to object query to exclude 0
I have a Linq query as below. 我有一个Linq查询,如下所示。
var DataSource = from m in product
select new { Class = m.Class, Id = (new Make(m.Id)).ProductName};
I instantiate a class called Make
and fetch the ProductName
based on the Id
. 我实例化一个名为
Make
的类,并根据Id
获取ProductName
。 Some of the Id's are 0. Is there a way I can exclude all the Id's that are 0? 有些Id为0。有什么办法可以排除所有为0的Id?
Sure, just do this: 当然,只要这样做:
var DataSource = from m in product
where m.Id != 0
select new
{
Class = m.Class,
Id = (new Make(m.Id)).ProductName
};
您正在寻找where
子句:
where m.Id != 0
var DataSource = from m in product
where m.Id != 0
select new
{
Class = m.Class,
Id = (new Make(m.Id)).ProductName
};
Try this: 尝试这个:
var DataSource = from m in product
where m.Id != 0
select new { Class = m.Class, Id = (new Make(m.Id)).ProductName};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.