实体框架与AssociateWith [英] Entity Framework vs. AssociateWith
问题描述
当我使用Linq2Sql时,可以通过在DataLoadOptions.AssociateWith方法中使用lambda表达式来过滤表.
When I use Linq2Sql I can filter a table by using a lambda-expression in the DataLoadOptions.AssociateWith method.
我用它来过滤使用的语言-因此,我有一个包含所有语言的语言表和一个包含对象的对象表.
I use this for filtering the used language - so I have a language table with all languages and a object table containing objects.
赞:
DataLoadOptions opt = ...;
opt.AssociateWith<DB.Objects>(o => o.Language.Where(p => p.Culture == CurrentUser.Culture));
如何使用实体框架做到这一点-我必须在其中使用.include(string)而不是dataloadoptions?
How to do that with the entity-framework - where I have to use .Include(string) instead of the dataloadoptions?
推荐答案
能否让我们知道您使用的是哪个版本的EF.
Can you please let us know which version of EF you are using.
但是,如果要使用"include"方法,则可能看起来像这样.
But saying that you want to use the "include" method, then it would probably look like this.
var result = dbContext.Objects.Include("Language").Where(p=>p.Culture == CurrentUser.Culture );
请注意,语言"应反映模型中导航属性名称中设置的内容. (因此请注意复数形式)
note that "Language" should reflect what is set in your navigation property name in your model. (so watch out for plurals)
这篇关于实体框架与AssociateWith的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!