我正在试图找出返回类型。看起来ToList()返回一个List,但我不确定它是什么类型。
var id = (from h in db.t_ref_harvest_type
where h.manner_of_take_id == methodOfTakeId &&
parsedSeasons.Contains((int)h.season) && h.active == true
select new { h.id, h.harvest_type }).ToList();
答案 0 :(得分:5)
返回了匿名类型列表,其中包含 id和类型作为属性。
当您在linq查询中编写Select new时,它会创建一个匿名类型,其中包含您在select new {}中添加的属性。
完整的aritlce:SQL to LINQ ( Visual Representation )
修改强>
@KeelRisk - 你不能从方法中返回匿名类型列表...如果你只想返回id而不是修改查询选择“List<int> lstid= (.....Select h.id).ToList<int>();
”而不是返回lstid..will do to you
List<int> lstid = (from h in db.t_ref_harvest_type
where h.manner_of_take_id == methodOfTakeId && parsedSeasons.Contains((int)h.season)
&& h.active == true
select h.id ).ToList();