When creating the first code collections, you can implement a custom class that implements ICollection. The code below is conceptual not relevant
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 truly support any collection that inherits from ICollection. We create a removable collection to support automatic deletions, and also create collections for child objects to reduce the size of our main object.