I’m having issues with merging the following object into another session:
Entity and it’s associations
Domain -> * Subdomains -> * Controls -> * Measures
The merge on the domain entity works, but it’s associations are not merged. How can i fix this?
using (var session = SessionFactoryContainer.Current.Get(sessionFactoryName).OpenSession())
{
using (var transaction = session.BeginTransaction())
{
try
{
session.Merge(domain);
transaction.Commit();
}
catch (Exception e)
{
transaction.Rollback();
throw;
}
}
}
Mappings
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Mapping;
using ISMSControl.Domain;
namespace ISMSControl.Infrastructure.Mappings
{
public class NDomainMapping : ClassMap<NDomain>
{
public NDomainMapping()
{
Table("domeinen");
Id(m => m.Id, "id").UnsavedValue(-1);
Map(m => m.Code, "code_1");
Map(m => m.Description, "omschrijving");
Map(m => m.Explanation, "toelichting");
Map(m => m.DateCreated, "createdat");
Map(m => m.CreatedBy, "createdby");
Map(m => m.DateModified, "modifiedat");
Map(m => m.ModifiedBy, "modifiedby");
HasMany(m => m.SubDomains)
.KeyColumn("domein")
.Inverse()
.Cascade.All();
}
}
}
I created my own datacontext and mapped the properties to the related columns. My ModelTranslator class translates the domain object to the type object i need for my own datacontext implementation.
I’m still not sure if this is the right solution, but it solved my problem for now.