c# - 明显不在 Entity Framework 中工作

标签 c# entity-framework-6

获取文档名称列表的函数,仅具有不同的...

public static List<DocumentTypeModel> GetUploadedDocumentsName(int TicketId)
{
    List<DocumentTypeModel> documents = new List<DocumentTypeModel>();
    using (var db = new UnitOfWork())
    {
        documents = db.tbl_TrnTicketDocument.Get(x => x.FK_TicketId == TicketId && x.IsActive == true).Select(s => new DocumentTypeModel()
        {
            DocumentTypeNameEnglish = s.tbl_MstDocumentType.DocumentTypeNameEnglish
        }).Distinct().ToList();
    }
    return documents;
}

目前的结果是这样的-

Affidavit in Case of Cancelled Will/No Will

Affidavit in Case of Cancelled Will/No Will

Allotment Letter

Allotment Letter

Death Certificate

Death Certificate

Lease Deed

Lease Deed

Photo Identity of Applicant

Photo Identity of Applicant

Possession Letter

Possession Letter

Registered/Unregistered Will

Registered/Unregistered Will

最佳答案

您可以像这样使用 groupby 并选择第一个选项:

List<DocumentTypeModel> documents = new List<DocumentTypeModel>();
using (var db = new UnitOfWork())
{
   documents = db.tbl_TrnTicketDocument.Get(x => x.FK_TicketId == TicketId && x.IsActive == true).Select(s => new DocumentTypeModel()
   {
   DocumentTypeNameEnglish = s.tbl_MstDocumentType.DocumentTypeNameEnglish
   }).ToList();

   documents = documents.GroupBy(x => x.DocumentTypeNameEnglish).Select(g => g.First());
}

关于c# - 明显不在 Entity Framework 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36307732/

相关文章:

c# - C# winforms中有像Flex中 "ViewStack"这样的控件吗?

c# - 在 .net core 2 解决方案中引用 .net 4.7 框架程序集

c# - 标识为 'Id' 的项目已存在于元数据集合中。参数名称 : item

c# - 使用 Entity Framework 6 的存储库模式更新记录

c# - 构建 C# EntityFramework IQueryable 表达式时遇到问题

c# - WCF:回调不是异步的

c# - sql server 手动增加订单id

c# - 添加 <asp :image> from codebehind

c# - 我应该把我的存储库放在哪一层?

.net - azure辅助角色中的DbConfiguration.SetConfiguration