There is a function and linq in it:
public Object Get(string title) { DbSet<Product> p; return p.Where(x => x.Title == title).Join(//Далее код) } Question: how can I ignore what is written in Where under a certain condition (for example, if title == null ) and continue further Join ???
public async Task<Object> Get(string title, string group = null, string category = null) { return _productContext.gropsAndProducts .Join(_productContext.groups, gap => gap.GroupId, g => g.Id, (gap, g) => new { Id = gap.Id, ProductId = gap.ProductId, GroupTitle = g.Title, GroupDiscription = g.Discription, CategoryId = g.CategoryId }) .Where(x => x.GroupTitle == group) .Join(_productContext.categories, g => g.CategoryId, c => c.Id, (g, c) => new { Id = g.Id, ProductId = g.ProductId, GroupTitle = g.GroupTitle, GroupDiscription = g.GroupDiscription, CategoryId = g.CategoryId, CategoryTitle = c.Title, CategoryDiscription = c.Discription }) .Where(x => x.CategoryTitle == category) .Join(_productContext.product, c => c.ProductId, p => p.Id, (c,p) => new { Id = c.Id, ProductTitle = p.Title, Price = p.Price, GroupTitle = c.GroupTitle, GroupDiscription = c.GroupDiscription, CategoryTitle = c.Title, CategoryDiscription = c.Discription }) .Where(x => x.ProductTitle == title) } Everything works with the condition if non-empty values are passed to the function.
Where(x => x.Title == title || title == null)? - tym32167 9:54 pmtitlecomesnull, then I would like everything to be withoutwhere- Vitaly Shebanitsif (title != null) p = p.where(...)? - tym32167 9:57 pmWhere(x => x.Title == title || title == null)doesn’t fit, if totitle == nullthen I need to select absolutely all entries - Vitaly Shebanits