2013-07-11 93 views
1

我有一個Linq查詢如下。linq to object query to exclude 0

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

我實例化一個名爲Make類以及基於Id獲取ProductName。 一些Id的是0. 有沒有辦法可以排除所有的Id是0?

回答

1

您正在尋找的where條款:

where m.Id != 0 
2

當然,只是這樣做:

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

試試這個:

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