此代码有什么问题?
List<CampaignManager_tbl> candidates = new List<CampaignManager_tbl>();
candidates = from cat in db.Events_Category_tbl
join can in db.Candidates_Info_tbl on cat.events_category_id equals can.events_category_id
where cat.events_info_id == events.events_info_id
select new CampaignManager_tbl {
events_category_name = cat.events_category_name,
candidates_fullname = can.candidates_fullname,
candidates_place = can.candidates_place
};
return View(candidates);
当我使用此方法仅查询一个表时,它可以工作,但是当我尝试这个时。它不起作用。
答案 0 :(得分:0)
您必须将IQueryable
转换为List
。您可以通过在Linq查询末尾添加.ToList()
来执行此操作。
List<CampaignManager_tbl> candidates = new List<CampaignManager_tbl>();
candidates = (from cat in db.Events_Category_tbl
join can in db.Candidates_Info_tbl on cat.events_category_id equals can.events_category_id
where cat.events_info_id == events.events_info_id
select new CampaignManager_tbl {
events_category_name = cat.events_category_name,
candidates_fullname = can.candidates_fullname,
candidates_place = can.candidates_place
}).ToList();
return View(candidates);