C# Linq到引用列表的对象

C# Linq到引用列表的对象,c#,linq,linq-to-entities,C#,Linq,Linq To Entities,我有两个完全不同的数据源,一个是关于客户端的详细信息,另一个是只有ClientID的站点,但由于系统的部分迁移,我无法在数据库级别连接它们(不过,这最终会发生!): 运行上面的代码会返回一个错误 “LINQ to实体无法识别该方法 'certssured.Model.Client.ClientSummary 查找(System.Predicate`1[CertsAssured.Model.Client.ClientSummary])” 我可以在这一步之后编写代码来执行任务,但随后必须将Clien

我有两个完全不同的数据源,一个是关于客户端的详细信息,另一个是只有ClientID的站点,但由于系统的部分迁移,我无法在数据库级别连接它们(不过,这最终会发生!):

运行上面的代码会返回一个错误

“LINQ to实体无法识别该方法 'certssured.Model.Client.ClientSummary 查找(System.Predicate`1[CertsAssured.Model.Client.ClientSummary])”

我可以在这一步之后编写代码来执行任务,但随后必须将ClientId保存到我的对象中,然后进行迭代。在选择方法期间,是否有方法从客户机列表中获取信息


谢谢

在设置数据库筛选/分页后,您可以使用
AsEnumerable
将IQueryable结果转换为内存中的IEnumerable,您可以在其中查找
客户端

result.Content = pageResult
        .AsEnumerable()
        .Select(a => new QuoteSearch
        {
            Accepted = a.Accepted,
            Created = a.Created,
            Id = a.Id,
            Customer = clients.Find(b => b.Id == a.ClientId).Name
        }).ToList();
如果有许多数据库字段,并且您不希望从数据库中获取所有字段,那么可以首先在IQueryable上过滤字段,类似于

result.Content = pageResult
        .Select(a => new                    // This filters in the database
        {                                   // to an anonymous type
            Accepted = a.Accepted,
            Created = a.Created,
            Id = a.Id,
            ClientId = a.ClientId
        })
        .AsEnumerable()                     // Convert to an IEnumerable 
        .Select(a => new QuoteSearch        // This is done in-memory
        {                                   // generating the real type
            Accepted = a.Accepted,
            Created = a.Created,
            Id = a.Id,
            Customer = clients.Find(b => b.Id == a.ClientId).Name
        }).ToList();

谢谢Joachim,工作得很好,谢谢你提供的额外信息
result.Content = pageResult
        .Select(a => new                    // This filters in the database
        {                                   // to an anonymous type
            Accepted = a.Accepted,
            Created = a.Created,
            Id = a.Id,
            ClientId = a.ClientId
        })
        .AsEnumerable()                     // Convert to an IEnumerable 
        .Select(a => new QuoteSearch        // This is done in-memory
        {                                   // generating the real type
            Accepted = a.Accepted,
            Created = a.Created,
            Id = a.Id,
            Customer = clients.Find(b => b.Id == a.ClientId).Name
        }).ToList();