Hi,
I'm tearing my hair over a basic functionality which I can't get to work.
I which to add or remove a child entity in the TransferFormValuesTo() function. My code is pretty simple:
protected override void TransferFormValuesTo(Product toUpdate, Product fromForm)
{
toUpdate.Category = fromForm.Category;
foreach (var file in fromForm.Files)
{
toUpdate.AddFile(file);
}
}
If I create the entity from scratch it works just fine, but if I edit an existing entity then NHibernate throws this exception:
NonUniqueObjectException
a different object with the same identifier value was already associated with the session: 7, of entity: MyProject.Domain.Entities.Product
Does anybody know what the cause of the exception can be. I know that it means that NHibernate somehow thinks I have to objects of the Product entity in memory somewhere but if I just skip the call to "toUpdate.AddFile(file)", everything is fine and all other properties are saved. BTW, here is the code for AddFile():
public virtual void AddFile(ProductFile file)
{
if (file != null && !files.Contains(file))
{
files.Add(file);
}
}
Thanks in advance!
/Ingo