C# EntityFramework按linq查询分组

C# EntityFramework按linq查询分组,c#,linq,linq-to-entities,entity-framework-6,C#,Linq,Linq To Entities,Entity Framework 6,我有以下两个表格: Account ---------- account_id **PK** account_name account_type_id **FK** Account_Type ------------- account_type_id **PK (FK in account table)** account_type_name account_type_reference 使用实体框架,我试图得到如下结果: DbSet.Where(Account => Account

我有以下两个表格:

Account
----------
account_id **PK**
account_name
account_type_id **FK** 

Account_Type
-------------
account_type_id **PK (FK in account table)**
account_type_name
account_type_reference
使用实体框架,我试图得到如下结果:

DbSet.Where(Account => Account.Account_Type.account_type_name == 'type1').ToList());
这是可行的,但是我不知道如何将GROUPBY添加到此语句中。我想按帐户类型id、帐户类型名称、帐户类型引用对它们进行分组,这样我就不会得到重复的行。我该怎么做


谢谢

您可以使用Linq GroupBy功能添加分组:

DbSet.Where(Account => Account.Account_Type.account_type_name == "type1")
    .GroupBy(x => x.Account_Type.account_type_id).ToList();

然后,您将得到一个组列表。然后,每个组都有一个键(account\u type\u id),并且组本身是account对象的IEnumerable

account\u type\u id
分组就足够了,因为它是唯一的(我希望如此)。