gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 15:04:51 25 4
gpt4 key购买 nike

我正在尝试找出返回类型。看起来 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 和 type 作为属性。

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

enter image description here

完整算法:SQL to LINQ ( Visual Representation )

编辑

@KeelRisk - 你不能从该方法返回匿名类型的列表......如果你只想返回 id 而不是将查询选择修改为“List<int> lstid= (.....Select h.id).ToList<int>();”然后返回 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();

关于c# - 此 Linq to SQL 返回的数据类型是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9696132/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com