2014-01-20 45 views
1

所有負載/刪除現有的實體,實體框架 - 通過多種Critereon

我購買的朱莉婭·勒曼書Programming DbContext並通過實例看,我看不出有任何的方式來加載具有大於1的現有實體搜索參數:從書

例子:

using (var context = new BreakAwayContext()) 
{ 
    var bay = (from d in context.Destinations 
       where d.Name =="Wine Glass Bay" 
       select d).Single(); 

    context.Destinations.Remove(bay); 
    context.SaveChanges(); 
} 

如果我想找到所有目的地where d.Name == "Wine Glass Bay" AND d.State = "CA"?如果沒有必要,我寧願不執行原始SQL。由於

回答

3

在C#中使用&&邏輯 「與」 操作符:

from d in context.Destinations 
where d.Name == "Wine Glass Bay" 
    && d.State == "CA" 
select d