When creating code first collections can you implement a custom class that implements ICollection. The code below is conceptual not actual
public class Product
{
public int ProductId { get; set; }
public string Name { get; set; }
public Category Category { get; set; }
}
public class Category
{
public int CategoryId { get; set; }
public string Name { get; set; }
//Want to Avoid This
public ICollection<Product> Products { get; set; }
//Use his instead of above
public ProductList ProductsInCategory {get;set;}
}
public class ProductsList :ICollection<Product>
{
public int DiscontinuedProductsCount
{
return internalList.Count();
}
//Icollection Methods Excluded
}
EF can indeed support any collection which inherits from ICollection. We create a deletable collection to support auto deletions and also create collections for child objects to keep the size of our main object smaller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With