简体   繁体   English

查询时 T4 中不存在 EF6 子关系

[英]EF6 Child Relations not Present in T4 on Query

I'm using Entity Framework 6 with a pretty simply DB using a repository pattern.我使用 Entity Framework 6 和一个非常简单的 DB 使用存储库模式。 From previous versions EF I never had any problems retrieving child entities as part of my POCO objects.从以前的 EF 版本中,我在检索子实体作为 POCO 对象的一部分时从未遇到任何问题。

For example if I have a Customer table and an account table where there is a 1-n relationship on the db, when I query the customer entity I would expect the customer entity to contain an array of Account entities, it never does, the array is always empty.例如,如果我有一个 Customer 表和一个 account 表,其中在 db 上有 1-n 关系,当我查询 customer 实体时,我希望 customer 实体包含一个 Account 实体数组,但它永远不会包含数组总是空的。

My queries are like:我的查询是这样的:

dataContext.Set<TBL_CUSOTOMER>().Find(id)  

Where dataContext is inheritted from DbContext.其中 dataContext 继承自 DbContext。

I'm pretty sure I'm missing really obvious我很确定我错过了非常明显的

它应该工作

dataContext.Set<TBL_CUSTOMER>().Include(x=>x.accounts).FirstOrDefault(x=>x.Id==id);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM