Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public IQueryable<TEntity> Find(Expression<Func<TEntity, bool>> predicate, params Expression<Func<TEntity, object>>[] includes)
- {
- var query = _entities.Where(predicate).AsQueryable();
- if (includes != null)
- {
- query = includes.Aggregate(query, (current, include) => current.Include(include));
- }
- return query;
- }
- public class Product : BaseEntity<long>
- {
- [MaxLength(100)]
- public string Name { get; set; }
- [MaxLength(100)]
- public string Barcode { get; set; }
- public int ShelfLife { get; set; }
- public int Weight { get; set; }
- public bool HasAllergens { get; set; }
- [ForeignKey("Id")]
- public int CustomerId { get; set; }
- public virtual ICollection<ProductIngredient> ProductIngredient { get; set; }
- }
- public class Ingredient : BaseEntity<long>
- {
- [MaxLength(100)]
- public string Name { get; set; }
- [ForeignKey("Id")]
- public int CustomerId { get; set; }
- public virtual ICollection<ProductIngredient> ProductIngredient { get; set; }
- }
- public class ProductIngredient : BaseEntity<long>
- {
- [ForeignKey("Id")]
- public long? ProductId { get; set; }
- [ForeignKey("Id")]
- public long? IngredientId { get; set; }
- }
- public class ProductDto
- {
- public long Id { get; set; }
- public DateTime CretedOn { get; set; }
- public DateTime UpdatedOn { get; set; }
- public string Name { get; set; }
- public string Barcode { get; set; }
- public int ShelfLife { get; set; }
- public int Weight { get; set; }
- public bool HasAllergens { get; set; }
- public int CustomerId { get; set; }
- public IList<IngredientDto> Ingredients { get; set; }
- }
- var results = await _productsRepository.FindAsync(p => p.Id == id, p => p.ProductIngredient);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement