我有一個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?
我有一個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?
您正在尋找的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
};
var DataSource = from m in product
where m.Id != 0
select new
{
Class = m.Class,
Id = (new Make(m.Id)).ProductName
};
試試這個:
var DataSource = from m in product
where m.Id != 0
select new { Class = m.Class, Id = (new Make(m.Id)).ProductName};