Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. public IQueryable<TEntity> Find(Expression<Func<TEntity, bool>> predicate, params Expression<Func<TEntity, object>>[] includes)
  2. {
  3. var query = _entities.Where(predicate).AsQueryable();
  4. if (includes != null)
  5. {
  6. query = includes.Aggregate(query, (current, include) => current.Include(include));
  7. }
  8. return query;
  9. }
  10.  
  11. public class Product : BaseEntity<long>
  12. {
  13. [MaxLength(100)]
  14. public string Name { get; set; }
  15. [MaxLength(100)]
  16. public string Barcode { get; set; }
  17. public int ShelfLife { get; set; }
  18. public int Weight { get; set; }
  19. public bool HasAllergens { get; set; }
  20. [ForeignKey("Id")]
  21. public int CustomerId { get; set; }
  22. public virtual ICollection<ProductIngredient> ProductIngredient { get; set; }
  23. }
  24.  
  25. public class Ingredient : BaseEntity<long>
  26. {
  27. [MaxLength(100)]
  28. public string Name { get; set; }
  29. [ForeignKey("Id")]
  30. public int CustomerId { get; set; }
  31. public virtual ICollection<ProductIngredient> ProductIngredient { get; set; }
  32. }
  33.  
  34. public class ProductIngredient : BaseEntity<long>
  35. {
  36. [ForeignKey("Id")]
  37. public long? ProductId { get; set; }
  38. [ForeignKey("Id")]
  39. public long? IngredientId { get; set; }
  40. }
  41.  
  42. public class ProductDto
  43. {
  44. public long Id { get; set; }
  45. public DateTime CretedOn { get; set; }
  46. public DateTime UpdatedOn { get; set; }
  47. public string Name { get; set; }
  48. public string Barcode { get; set; }
  49. public int ShelfLife { get; set; }
  50. public int Weight { get; set; }
  51. public bool HasAllergens { get; set; }
  52. public int CustomerId { get; set; }
  53. public IList<IngredientDto> Ingredients { get; set; }
  54. }
  55.  
  56. var results = await _productsRepository.FindAsync(p => p.Id == id, p => p.ProductIngredient);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement