问题描述:

I have a child entity:

public class PhoneNumber : KeyedEntityBase

{

public string Number { get; set; }

public string Extension { get; set; }

}

that exists in multiple parents:

public class Customer : KeyedEntityBase

{

public string Name { get; set; }

public PhoneNumber PhoneNumber { get; set; }

}

public class Vendor : KeyedEntityBase

{

public string VendorName { get; set; }

public PhoneNumber PhoneNumber { get; set; }

}

When I want to delete a PhoneNumber from one of the parents I just null it out. Is there a way I can make Entity Framework handle deleting orphan PhoneNumber instances when using a Repository pattern? I believe NHibernate's all-delete-orphan cascade mode does this. Now to do this I have to create a PhoneNumberRepository and explicitly delete the PhoneNumber after I null it out on the parent, and this smells.

相关阅读:
Top