实体框架过滤器导航属性不起作用 [英] Entity FrameWork Filter Navigation Properties Does Not Work

查看:87
本文介绍了实体框架过滤器导航属性不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到我需要从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

<一个href="http://data.uservoice.com/forums/72025-entity-framework-feature-suggestions/suggestions/1015345-allow-filtering-for-include-extension-method"相对=nofollow>请求该功能

请参见 https://msdn.microsoft.com/en-us/data/jj574232#explicitFilter

<一个href="http://stackoverflow.com/questions/5324931/linq-query-how-sort-and-filter-on-eager-fetch/5325160#5325160">LINQ查询 - 如何排序和过滤器预先抓取

这篇关于实体框架过滤器导航属性不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆