I have stores with products, I want to get all stores even if the store doesn't have active products
here are the entity classes
class Store
{
[Key]
public Guid UId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public DateTime Created { get; set; }
public DateTime Updated { get; set; }
public bool Inactive { get; set; }
public virtual ICollection<Product> Products { get; set; }
}
class Product
{
[Key]
public Guid Id { get; set; }
public Guid StoreUid { get; set; }
public virtual Store Store{ get; set; }
public string Name { get; set; }
public string Description { get; set; }
public DateTime Created { get; set; }
public DateTime Updated { get; set; }
public bool Inactive { get; set; }
}
the statement I'm using now is:
using (var context = new DbContext())
{
context.Stores.
.AsNoTracking()
.Where(store => !store.Inactive)
.Include(x => x.Products)
.ToList();
}
I tired
using (var context = new DbContext())
{
context.Stores.
.AsNoTracking()
.Where(store => !store.Inactive && store.Products.Any(p=>!p.Inactive))
.Include(x => x.Products)
.ToList();
}
but I didn't get the store without any linked product to it.
the think is that I want to be able to get the Store.Products as Null or empty collection I want to avoid as much for each statement and try to do it SQLish.. because in SQL is much easier to do this but I need the Include for nesting