我意识到我需要从EF的导航属性过滤掉一些实体。我发现微软自己的网页上这样的:
I realised I need to filter out some entities from the navigation property in EF. I found Microsoft's own page on this:
https://msdn.microsoft.com/en-us/data/ jj574232#explicitFilter
我抄他们的code到vb.net尽可能接近,因为我可以为我的实体。我改变后没有工作,所以它应该过滤掉一切过滤器(ID = -99)。这仍然没有奏效。它得到了发票,但不过滤任何的相关发票的详细信息。
I have copied their code into vb.net as closely as I can for my entities. I changed the filter after it did not work so that it should filter out everything (id = -99). This still did not work. It gets the Invoice but does not filter any of the related Invoice details.
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
任何想法?我的code似乎非常密切配合梯也尔。我曾经尝试这样做有和没有.INCLUDE。
Any ideas? My code seems to match thiers very closely. I have tried this with and without the ".include".
推荐答案
请注意,这是当前无法滤除相关实体被加载。包括总会带给所有相关实体。
实体框架团队正在为此努力。它是一种即将到来的功能
Entity framework team are working on it. Its a upcoming feature
请求该功能
请参见 https://msdn.microsoft.com/en-us/data/jj574232#explicitFilter
LINQ查询 - 如何排序和过滤器预先抓取
相关推荐
最新文章