【发布时间】:2015-07-23 14:00:18
【问题描述】:
我意识到我需要从 EF 的导航属性中过滤掉一些实体。我在此找到了微软自己的页面:
https://msdn.microsoft.com/en-us/data/jj574232#explicitFilter
我已尽可能将他们的代码复制到 vb.net 中以用于我的实体。我在它不起作用后更改了过滤器,以便它应该过滤掉所有东西(id = -99)。这仍然没有奏效。它获取发票,但不过滤任何相关的发票详细信息。
Dim Inv = MyBase.Context.Invoices.Include(Function(x) x.InvoiceDetails).Where(Function(x) x.id = id).FirstOrDefault
MyBase.Context.Entry(Inv).Collection(Function(x) x.InvoiceDetails).Query().Where(Function(d) d.id = -99).Load()
Dim cc = Inv.InvoiceDetails.Count
If cc > 1 Then
Debug.Write(cc)''This should not run as all should be filtered out but it does
End If
有什么想法吗?我的代码似乎与它们非常接近。我已经尝试过使用和不使用“.include”。
【问题讨论】:
-
所以您不需要任何 InvoiceDetails?为什么不像示例中那样在发票上使用 Find?如果您随后需要 InvoiceDetails 的子集,请将查询应用于集合。
-
@NDC 您无法使用 where 过滤包含语句。在显式过滤器中,它们只包含 select 语句
标签: .net vb.net entity-framework