English 中文(简体)
附有实体目标清单的物体清单
原标题:Object with List of objects in which has a list of objects Linq to Entities

我将林克用于各实体,我只想呼吁数据库获得一些数据。

我有一个账户标本,可以有多个公司参与。 每个公司都有许多地点。 我可以把公司名单拿到账户中,没有任何问题。 问题在于为每个公司找到地点,并将其全部重新纳入账户目标。 我的法典是:

    public Account GetAccountByUserId(int userId)
    {
        IQueryable<Account> oq = _context.Accounts;

        oq = oq.Include(x => x.Companies);

        oq = oq.Include(x => x.Companies.SelectMany(l => l.Locations); //I was just guessing here, this throws the error below

        Account acct = oq.Single(x => x.Users.Any(y => y.Id == userId));
        return acct;
    }

The error the .SelectMany throws: The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties. Parameter name: path

这甚至可能无法做到,但如果没有另一种方式? 我只想呼吁数据库。

最佳回答

你们是否试图将公司和地点包括在内:

_context.Accounts.Include("Companies.Locations");
问题回答

暂无回答




相关问题
LINQ Training: Native SQL Queries to LINQ

Can anyone point out some good LINQ training resources. Mostly interested in getting some developers that are very skilled with SQL up to speed using Lambda and LINQ queries. They are struggling with ...

How can i write Linq2Entities Query with inner joins

How can I get data from these related entities. I want to get these columns only: Term.Name , related Concept_Term.Weight, related Concept.Id I wrote the SQL but I don t want to use select t....

Linq to enties, insert foreign keys

I am using the ADO entity framework for the first time and am not sure of the best way of inserting db recored that contain foreign keys. this is the code that i am using, I would appreciate any ...

Linq to entity timing problem

I created a data model that has some views from my database as entities,when I create a linq statment that has part of this view s entities ,the time processor take to execute the linq statment is ...

热门标签