相关疑难解决方法(0)

使用实体框架加载所有子实体

我有这样的数据模型

数据模型

我想将对帐中的所有相关实体加载到Reconciliation对象中.

目前,我可以找到将所有相关的entites加载到单个Recon的唯一方法是多个列表.但我想加载一个Reconciliation对象中的每个相关实体.如果可能的话,优雅的方式.

Reconciliation recon = db.Reconciliations
  .Where(r => r.ReconNum == 382485).First();

List<ReconciliationDetail> reconDetails = recon.ReconciliationDetails.ToList();
List<JrnlEntryDetail> jrnlDetails = reconDetails.Select(r => r.JrnlEntryDetail).ToList();
List<JrnlEntry> jrnl = jrnlDetails.Select(j => j.JrnlEntry).ToList();

List<ARInvoice> invoices = jrnl.SelectMany(j => j.ARInvoices).ToList();
List<ARInvoiceDetail> invoicesDetail = invoices
  .SelectMany(i => i.ARInvoiceDetails).ToList();

List<ARCredMemo> credmemos = jrnl.SelectMany(j => j.ARCredMemoes).ToList();
List<ARCredMemoDetail> credmemosDetail = credmemos
  .SelectMany(c => c.ARCredMemoDetails).ToList();

List<IncomingPay> incomingPays = jrnl.SelectMany(j => j.IncomingPays).ToList();
List<IncomingPayDetail> incomingPaysDetail = incomingPays
  .SelectMany(i => i.IncomingPayDetails).ToList();

// ... and so on for outgoing pays, AP …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework-5

22
推荐指数
2
解决办法
6万
查看次数

如何在OfType()之后使用Include()?

我试图在Entity Framework模型中急于加载派生类的属性.

在包含使用Include()的属性之前,我已经阅读了所有 必须首先使用OfType()过滤集合 地方:

var persons = Context.Persons
                     .OfType<Employee>()
                     .Include("Compensation")
Run Code Online (Sandbox Code Playgroud)

我不知道如何让Include()工作,因为在我的情况下,Persons是DbSet,OfType()返回IQueryable而IQueryable没有定义Include()方法.

.net c# entity-framework entity-framework-5

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

标签 统计

c# ×2

entity-framework-5 ×2

.net ×1

entity-framework ×1