In our project we are following Domain Driven Design with entity framework. Recently i came upon one issue where i want to delete a object from collection . Lets say Customer have collection of purchase. I want to remove the particular purchase of one customer.
public class Customer
{
public int ID { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public virtual ICollection<Purchase> Purchases { get; set; }
}
public class Purchase
{
public int ID { get; set; }
public int CustomerId { get; set; }
public DateTime PurchaseDate { get; set; }
}
I tried to remove the purchase by
customer.Purchases.Remove(purchase);
but the above code removed only the relation not deleting the purchase from db . I want to remove them from db.
So to make that work i have given that responsibility to Repository and used context object inside repository to remove the purchase.
repository.DeletePurchase(purchase);
Is the above is right approach in Domain Driven Design or any possibilities to move the delete behavior within entity?
Pleas help me the follow the best practice to implement DDD.