以下に示すエンティティフレームワークコードがあります。where条件で次のエラーが発生します。
デリゲート型ではないため、ラムダ式を型'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();
}
}