query.Single()
That's it.
leppie
2010-06-25 10:26:34
id = (from m in stock.StockTools
from ss in stock.RefStockStatus
where (m.statusid == 3 || m.statusid == 5) &&
ss.id == m.statusid && m.id == ItemID
select m.id).FirstOrDefault();
if you want to retrieve a single result user FirstOrDefault() or First().
If you use First()
and the result is null.It will throws exception but not in FirstOrDefault()
.
var query = (from m in stock.StockTools
from ss in stock.RefStockStatus
where (m.statusid == 3 || m.statusid == 5) &&
ss.id == m.statusid && m.id == ItemID
select m.id).FirstOrDefault();