urfnet / URF.Core

Unit of Work & Repositories Framework - .NET Core, NET Standard, Entity Framework Core. 100% extensible & lightweight.
https://github.com/urfnet
MIT License
309 stars 62 forks source link

How to implement Conditional Include using URF.Core #35

Closed ydlkrishna closed 6 years ago

ydlkrishna commented 6 years ago

Please help me to implement Conditional Include something like below... using URF.Core

https://www.bartwolff.com/Blog/2017/08/19/entity-framework-conditional-includes return _context.Products .Where(x => x.Id == id) .Select(x => new { p = x, r = x.Resources.Where(y => y.LanguageCode.Equals(languageCode)) }) .AsEnumerable() .Select(x => x.p) .FirstOrDefault();

tonysneed commented 6 years ago

@ydlkrishna The blog post you reference encapsulates the conditional include in the GetProduct method of a ProductRepository. You can do the same thing with URF by creating your own ProductRepository that extends Repository<Product>, where you will have access to the DbContext and can use it to implement the kind of query you see here.