I have a class that calls ICB that has a property of type list of ICBResource, that is possible to associate many Resources to one ICB, the problem is when I want to delete a Resource associated with ICB that is not truly deleted and only set true in an deleted boolean property, the resources deleted still return from DB.
Example:
If this ICB has 10 resources associated but later 3 of resources were deleted, I want to list only the 7 remaining.
There is a way to implement a conditional for the .includes ?
// ICB class
public class ICB
{
public ICB()
{
ICBResources = new List<ICBResource>();
}
public int ICBId { get; set; }
public string Location { get; set; }
public ICollection<ICBResource> ICBResources { get; set; }
}
// Resource class
public class ICBResource
{
public int ICBResourceId { get; set; }
public virtual ICB ICB { get; set; }
public string name{ get; set; }
public bool Deleted { get; set; }
}
//here is my Repository and how I select my ICB with the resources associated
public ICB GetICB(int id)
{
return GetDbSet<ICB>()
.Include("ICBResources")
.SingleOrDefault(i => i.ICBId == id);
}
There is a way to include another conditional like a Where(i => i.ICBResources.Where(r=> !r.deleted);