[英]Loading three tables using Entity Framework include and lazy loading
I am using Entity Framework code-first, I have 3 tables, TableA
is the master table, TableB
is master table of TableC
.我首先使用实体框架代码,我有 3 个表, TableA
是主表, TableB
是TableC
的主表。 I have reference key of TableA
in TableC
, it means to load TableB
, I have to go through TableC
.我在TableC
中有TableA
的引用键,这意味着加载TableB
,我必须通过TableC
到 go 。
TableA has columns PKA, Col1A, Col2A TableB has Columns PKB, Col1B, Col2B TableC has Columns PKC, Col1C, Col2C TableA 具有 PKA、Col1A、Col2A 列 TableB 具有 PKB、Col1B、Col2B 列 TableC 具有 PKC、Col1C、Col2C 列
Can someone please let me know how I can incorporate in my Linq query in Entity Framework and load all those three tables using include statement and write a Linq query, any help please - thanks in advance.有人可以让我知道如何将我的 Linq 查询合并到 Entity Framework 中,并使用 include 语句加载所有这三个表并编写 Linq 查询,请提供任何帮助 - 在此先感谢。
As i take it, TableC
has dependency to both A and B. and you want to query TableC
for its values along with respective values from A,B.正如我所认为的, TableC
对 A 和 B 都有依赖性,并且您想查询TableC
的值以及来自 A、B 的相应值。 If my assumption is right then you are looking for:如果我的假设是正确的,那么您正在寻找:
var list = context.TableC
.Include(t => t.TableACollection)
.Include(t => t.TableBCollection);
for selecting only certain fields from those tables:仅从这些表中选择某些字段:
var list = context.TableC
.Include(t => t.TableACollection.Select(c => c.Col1A))
.Include(t => t.TableBCollection.Select(c => c.Col1B));
Hope it helps.希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.