Writing a unit test I have a ContactEntity and an EmailEntity. I have tried every possible scenario of the Association Attribute I can think of and I can't get this to happen...
- create contact,
- add email to contact (x3),
- save contact,
- remove email,
- save contact,
- remove email,
- save contact,
- remove email,
- save contact,
Assert - Table Emails -> Count == 0
The three emails are always left in the database. They're not assigned to the contact any longer and I do admit I think the application would run fine. Meaning if I load up my contact now, it doesn't have any emails. In my mind however, these emails are orphaned and should not be in the table.
Help?
[HierarchyRoot]
[TableMapping("Contacts")]
public partial class ContactEntity : BaseEntity//, IIdentifiable<int>
{
[Key, Field]
public int Id { get; private set; }
[Field(Length = 30)]
public string First { get; set; }
[Field(Length = 50)]
public string Last { get; set; }
[Field(Length = 30)]
public string Nick { get; set; }
[Field]
public string Website { get; set; }
[Field(Nullable = true)]
public AddressEntity Address { get; set; }
[Field]
public EntitySet<EmailEntity> Emails { get; set; }
[Field]
public EntitySet< PhoneEntity > Phones { get; set; }
}
[HierarchyRoot]
[TableMapping("Emails")]
public partial class EmailEntity : BaseEntity//, IIdentifiable<int>
{
[Key, Field]
public int Id { get; private set; }
[Field]
public EmailType Type { get; set; }
[Field(Length = 320)]
public string Address { get; set; }
[Field]
public bool IsPublic { get; set; }
//[Association(PairTo = "Emails")]
[Field]
[Association(PairTo = "Emails", OnOwnerRemove = OnRemoveAction.Cascade, OnTargetRemove = OnRemoveAction.Default)]
public ContactEntity Contact { get; set; }
}
asked
Oct 04 '13 at 17:52
Dave Jellison Fabnu
9●3●3●6
They also seem to remain after I remove the contact. Also, I'm trying to handle DTO<-->Entity mapping (you may have guessed), what's the preferred method of iterating an EntitySet and removing certain items? I'm building an id list, then looping, then removing, feels kinda clunky.
I lied, Cascade+Cascade worked, sorry. I swore I tried this before and it threw an exception.