1

我有一个如下的 Linq 查询。

var DataSource = from m in product
                 select new { Class = m.Class, Id = (new Make(m.Id)).ProductName};

我实例化了一个名为Make并获取ProductName基于Id. 一些 ID 为 0。有没有办法可以排除所有为 0 的 ID?

4

4 回答 4

2

当然,只需这样做:

var DataSource = from m in product
                 where m.Id != 0
                 select new
                 {
                     Class = m.Class,
                     Id = (new Make(m.Id)).ProductName
                 };
于 2013-07-11T19:11:21.230 回答
1

您正在寻找以下where条款:

where m.Id != 0
于 2013-07-11T19:11:16.353 回答
1
var DataSource = from m in product
                 where m.Id != 0
                 select new
                 {
                     Class = m.Class,
                     Id = (new Make(m.Id)).ProductName
                 };
于 2013-07-11T19:12:11.593 回答
1

试试这个:

var DataSource = from m in product
                               where m.Id != 0
                               select new { Class = m.Class, Id = (new Make(m.Id)).ProductName};
于 2013-07-11T19:12:18.483 回答