Created
December 27, 2016 01:37
-
-
Save ismaelgasparin/7b7ee81e6a8483bf73154668d41f06ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public IQueryable<T> GetAll(params Expression<Func<T, object>>[] includes) | |
{ | |
IQueryable<T> result = Context.Set<T>(); | |
if (includes.Any()) | |
{ | |
foreach (var include in includes) | |
{ | |
result = result.Include(include); | |
} | |
} | |
return result; | |
} | |
public T Get(Expression<Func<T, bool>> predicate, params Expression<Func<T, object>>[] includes) | |
{ | |
var result = GetAll(); | |
if (includes.Any()) | |
{ | |
foreach (var include in includes) | |
{ | |
result = result.Include(include); | |
} | |
} | |
return result.FirstOrDefault(predicate); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var product = _productRepository.Get(i => i.Id == productId, | |
i => i.Categories); | |
var productList = _productRepository.GetAll(i => i.Categories); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Acho que voce poderia passar o predicate e os includes direto para o GetAll e depois so dar 1 firstOrDefault, so para nao precisar fazer essa loga do includes.Any() 2 vezes.