过滤包含的导航属性EF [英] filtering an included navigation property EF
问题描述
大家好。
我试图包含符合特定条件的导航属性,但include方法不支持。所以我该怎样解决这个问题?
我希望它的代码是这样的:
ctx.GetAll()。include(o => o.NavProp.Where(p => p.Id == someId);
使用Projection返回匿名类型,所以我必须创建一个强制定义的类型来封装那些返回的项目,然后使用这个新类型的列表填充我的TreeView。这工作正常,但它需要大量的工作,因为当我想要保存新实体我总是创建一个新的实体并用我的新类型属性填充它的属性。
我很想知道我是否可以使用包含第一种方法方法。
谢谢你的时间。
i希望它很清楚。
尝试一下:
ctx.GetAll()。包含(o => o.NavProp)。其中(p => p.NavProp.Id == someId);
hello everyone.
am trying to include navigation properties that meet a specific condition but the include method doesn't support that.so how can i solve this?
the code i wish it to work is this:
ctx.GetAll().include(o=>o.NavProp.Where(p=>p.Id==someId);
using Projection return anonymous types so i had to create a stongly defined type to encapsulate those returned items and then populate my TreeView with a list of this new type.this works fine but it require a lot of work because when i want to save new entities i have allways to create a new entity and fill it's properties with my new type properties.
I love to know if i can do the first approach with include method.
thank you for your time.
i hope it's clear.
Try this out:
ctx.GetAll().Include(o=>o.NavProp).Where(p=>p.NavProp.Id==someId);
这篇关于过滤包含的导航属性EF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!