这段代码中select语句的含义是什么? [英] What is the meaning of select statement in this code?
本文介绍了这段代码中select语句的含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
List<int> obj =
datacontext.tblAdverts
.Where(i => i.BusinessUserId == id)
.GroupBy(i => i.Plans)
.Select(i => i.Key.Value).ToList();
推荐答案
List< int> obj = datacontext.tblAdverts
//构建集合#1:创建tblAdverts中所有条目的集合,其中条目的BusinessUserId与变量'id
。其中(i => i.BusinessUserId == id)
//构建集合#2:分析集合#1以构建组的集合,其中每个组(序列)包含集合#1中的内部对象计划相同的那些项目。
.GroupBy(i => i.Plans)
//构建集合#3:通过集合#2中的每个组并获取Key.Value整数属性,将其添加到集合#3
.Select(i => i.Key .Value)
//评估/渲染/处理内部Linq运算符创建的临时结构到类型列表'int
.ToList();
List<int> obj = datacontext.tblAdverts
// build Collection#1: create a collection of all entries in tblAdverts where the entry's BusinessUserId matches the value of the variable 'id
.Where(i => i.BusinessUserId == id)
// build Collection#2: analyze Collection#1 to build a Collection of Groups, where each Group (a sequence) contains those items in Collection#1 whose inner object 'Plans is identical.
.GroupBy(i => i.Plans)
// build Collection#3: go through each Group in Collection#2 and get the Key.Value integer property, add it to Collection#3
.Select(i => i.Key.Value)
// evaluate/render/process the temporary structures created by the internal Linq operators into a List of Type 'int
.ToList();
您是按结果分组选择的, K ey 在这里意味着你根据你所做的分组。 (此处计划),因此您选择每个组结果的 Plans.Value 属性。这里的值可能是属性,或者如果它是Nullable类型,则最可能的是 Nullable< t> .Value Property [ ^ ]
you are selecting from group by results, Key means here based on what you have done the grouping. ( here Plans), so you selecting Plans.Value property of each group results. Here value may be a property or if it is a Nullable type then most probable it is Nullable<t>.Value Property [^]
这称为LINQ(语言集成查询),借助后端将其转换为普通Sql您还可以使用名为 LINQPAD 的非常好的工具查看查询[ ^ ]
在此声明中您已提及,此查询
返回整数列表来自名为tblAdvert的表在其上下文的帮助下,即tblAdverts(通常上下文名称是复数),其中根据BusinessUserId添加过滤器并按计划列分组,然后选择键。
这一般是这个linq的意思。
但我不知道你为什么在这里使用key.Value。
我希望我能让你明白。
回复你的疑问。
谢谢。
This is called LINQ(Language Integrated Queries), with the help of which which at the back end this gets converted to normal Sql queries which you can also check using a very nice tool called LINQPAD[^]
Here in this statement you have mentioned, this query
returns a list of integers from the Table named tblAdvert with the help of its context i.e. tblAdverts(generally context names are pluralized), where a filter is added based on the BusinessUserId and Grouped by plans column and then select the key.
This iswhat in general this linq means.
But I am unaware of why you have used key.Value here.
I hope I could make you understand somehow.
Post back your queries if any.
Thanks.
这篇关于这段代码中select语句的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文