Hey,
I am fairly green behind the ears with LLBLGen, so please forgive me if the answer should be obvious from documentation. Anyway, here goes:
I have Announcement entities which are in a m:n relation to Organization entities. When editing a single Announcement, I would like to set which Organizations it corresponds with. Essentially, I am dealing with updating the collection of "organizations" that a given "announcement" is related to.
Here is my attempt at the code:
This would have happened at some point before the method I'm exploring:
announcement = new AnnouncementEntity(id);
This is the code I'm having trouble with:
announcement.AnnouncementOrganization.Clear();
foreach (OrganizationEntity org in selectedOrganizations)
{
AnnouncementOrganizationEntity currentJoin = new AnnouncementOrganizationEntity();
currentJoin.Announcement = announcement;
currentJoin.Organization = org;
announcement.AnnouncementOrganization.Add(currentJoin);
}
announcement.Save(true);
The trouble is getting the Clear() to be persisted. New relation entities get created, but old ones aren't getting removed. As I understand from documentation, I need to track remove actions using a RemovedEntitiesTracker, and then use a Unit of Work to make removing the relation entities, and adding new ones occur in the same transaction. However, I suspect I'm making it much more complicated than it needs to be.
Ideally, I would want something that works something like this:
announcement.Organizations.Clear();
foreach (OrganizationEntity org in selectedOrganizations)
{
announcement.Organizations.Add(org);
}
announcement.Save(true);
Thanks!