相关疑难解决方法(0)

Linq-to-entities - Include()方法未加载

如果我使用连接,则Include()方法不再有效,例如:

from e in dc.Entities.Include("Properties")
join i in dc.Items on e.ID equals i.Member.ID
where (i.Collection.ID == collectionID) 
select e
Run Code Online (Sandbox Code Playgroud)

e.Properties 没有加载

没有连接,Include()可以工作

背风处

linq entity-framework

46
推荐指数
2
解决办法
5万
查看次数

加入并包含在实体框架中

我有以下查询linq到实体.问题是它似乎没有加载"标签"关系,即使我已经包含了它的东西.如果我不加入标签,它工作正常,但我需要这样做.

            var items = from i in db.Items.Include("Tags")
                        from t in i.Tags
                        where t.Text == text
                        orderby i.CreatedDate descending
                        select i;
Run Code Online (Sandbox Code Playgroud)

有没有其他方式来询问此查询?也许拆分或什么?

.net c# sql linq entity-framework

29
推荐指数
1
解决办法
6万
查看次数

如何使用C#动态添加Include到ObjectSet <Entity>?

我想Include从输入中动态添加s params[].我怎样才能做到这一点?

这是我的代码

IQueryable<Work> query = this.ObjectContext.Works
    .Include("EmployeeSender.Person")
    .Include("EmployeeReceiver.Person")
    .Include("WorkCode")
    .Include("WorkFlowStep.WorkFlowFormState")
    .Include("WorkFlow")
    .Include("WorkRoot.EmployeeSender.Person")
    .Include("WorkParent");
Run Code Online (Sandbox Code Playgroud)

c# entity-framework

4
推荐指数
1
解决办法
5135
查看次数

为什么 Include 没有任何效果?

我正在执行以下 LINQ 查询,该查询有效但不返回导航属性 Person 填充,我得到null.

public IEnumerable<SharePeople> GetSharePeopeByCarId(int carId)
{
    return from q in _context.Cars
           join s in _context.Shares 
               on q.CarId equals s.Car.CarId
           join p in _context.SharePeople.Include(p => p.Person) 
               on s.ShareId equals p.ShareId
           where q.CarId == carId
           select p;
}
Run Code Online (Sandbox Code Playgroud)

我不知道为什么,因为当我使用常规扩展方法_context.SharePeople.Include(p => p.Person)时。

c# linq extension-methods entity-framework

1
推荐指数
1
解决办法
461
查看次数

标签 统计

entity-framework ×4

c# ×3

linq ×3

.net ×1

extension-methods ×1

sql ×1