问题描述
您好,我创建了此Linq查询
Hi I created this Linq query
var k = from account in _session.All<AccountDetail>()
join subscriber in _session.All<Subscriber>() on account.ID equals subscriber.AccID
join subscriberServices in _session.All<SubscriberServce>() on subscriber.ID equals subscriberServices.UserID
join paymentMethod in _session.All<PaymentMethod>() on subscriberServices.PaymentMethod_ID equals paymentMethod.ID
join paymentFrequency in _session.All<PaymentFrequency>() on subscriberServices.PaymentFrequency_ID equals paymentFrequency.ID
group account by new {AccID= account.ID,paymentFrequency= paymentFrequency.Description,paymentMethod= paymentMethod.Description} into G
select new GenerateInvoiceData() { AccID = G.Key.AccID};
我听不懂
group account by new {AccID= account.ID,paymentFrequency= paymentFrequency.Description,paymentMethod= paymentMethod.Description} into G
当我不受匿名类型的限制时,为什么要指定account
,即可以输入paymentFrequency.Description.
why do I specify account
when I'm not restricted to it in the anonymous type i.e. I can type paymentFrequency.Description.
推荐答案
group account
部分说明您希望每个组中的元素是什么. by new { ... }
是您希望每个组的 key .这不限于成为元素信息的一部分.
The group account
part is saying what you want the elements in each group to be. The by new { ... }
is what you want the key for each group to be. That's not restricted to being part of the information in an element.
作为最简单的示例,您可能会:
As a simplest example, you might have:
from person in people
group person.FirstName by person.LastName
这将为您提供组,其中每个组的键是该组中代表的所有人的姓氏,每个组的每个元素都是某人的名字.
which would give you groups where the key of each group was the last name of all the people represented in the group, and each element of each group would be the first name of someone.
您可能想阅读我的Edulinq博客文章中的两篇:
You might want to read two of my Edulinq blog posts:
- How query expressions work
- The
GroupBy
method
这篇关于需要帮助通过加入了解Linq小组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!