OK...
I have a class 'Summary' that has an IList that holds a list of 'Project' classes, representing a one-to-many relationship. This is mapped correctly and saving a Summary causes the list of Project classes to to be saved to the database correctly as well.
The Problem: if I programmatically add a Project to the Summary class's IList, then try to save the Summary class, I get a Foriegn Key violation in my database because the Project's SummaryID field is still 0 (it never gets set)
Now, I understand that this doesn't make much sense, becuase in a normal situation, I should be able to just set the SummaryID property of the Project class when I add it to the Summary class's IList.
However, in this particular situation that will not work because I am serializing these object from XML which user's need to modify in a disconnected environment, so I am unable determine what value the database will assign for the ID fields, as I am using identities
Is there a way to get around setting the ID feilds of an object that Is being added to the collection of another object that is already in the database?
|