Entity Framework vs. AssociateWith

2019-05-05 07:13发布

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.

Like:

DataLoadOptions opt = ...;
opt.AssociateWith<DB.Objects>(o => o.Language.Where(p => p.Culture == CurrentUser.Culture));

How to do that with the entity-framework - where I have to use .Include(string) instead of the dataloadoptions?

1条回答
萌系小妹纸
2楼-- · 2019-05-05 07:59

Can you please let us know which version of EF you are using.

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)

查看更多
登录 后发表回答