我有如下所示的实体框架代码。在 where 条件下出现以下错误。
无法将 lambda 表达式转换为类型“bool”,因为它不是委托类型
如何克服这个错误?这个错误的原因是什么?
static void Main(string[] args)
{
ClubCreation();
List<Club> selectedClubs = GetClubs("club1");
}
public static void ClubCreation()
{
string connectionstring = "Data Source=.;Initial Catalog=NerdDinners;Integrated Security=True;Connect Timeout=30";
using (var db = new NerdDinners(connectionstring))
{
Club club1 = new Club();
club1.ClubName = "club1";
Club club2 = new Club();
club2.ClubName = "club2";
Club club3 = new Club();
club3.ClubName = "club3";
db.Clubs.Add(club1);
db.Clubs.Add(club2);
db.Clubs.Add(club3);
int recordsAffected = db.SaveChanges();
}
}
public static List<Club> GetClubs(string clubName)
{
string connectionstring = "Data Source=.;Initial Catalog=NerdDinners;Integrated Security=True;Connect Timeout=30";
using (var db = new NerdDinners(connectionstring))
{
Club club1 = new Club();
Club club2 = new Club();
Club club3 = new Club();
var query = from o in db.Clubs
where (p => p.ClubName == "club1")
select o;
return query.ToList();
}
}