C# 此Linq to SQL上返回的数据类型是什么?

C# 此Linq to SQL上返回的数据类型是什么?,c#,linq-to-sql,c#-3.0,C#,Linq To Sql,C# 3.0,我想弄清楚退货类型。看起来ToList()返回一个列表,但我不确定是什么类型 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

我想弄清楚退货类型。看起来ToList()返回一个列表,但我不确定是什么类型

 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();

它是返回的匿名类型的列表,其中包含id和类型作为属性

当您在linq查询中写入Select new时,它将使用您在Select new{}中指定的属性创建匿名类型

完整算术:

编辑


@KeelRick-您不能从方法返回匿名类型的列表…如果您只想返回id而不想修改查询,请选择“
list lstid=(..…选择h.id).ToList();
”并返回lstid..即可

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(); 
List lstid=(从db.t\u ref\u harvest\u类型中的h开始)
其中h.way\u of_take\u id==methodOfTakeId&&parsedSeasons.Contains((int)h.season)
&&h.active==true
选择h.id).ToList();

好,那么在我的方法中应该返回什么类型?它只是返回变量id。或者更好地说,如何返回匿名类型的列表?@KeelRisk-您不能从方法返回匿名类型的列表…如果您只想返回id,请将query select修改为“List lstid=(..select h.id).ToList();”然后返回lstid..将对您有用确定,我想我需要循环检查结果并取出ID。谢谢