我在将以下对象合并到另一个会话时遇到问题:
实体及其关联
域 -> * 子域 -> * 控件 -> * 措施
域实体上的合并有效,但它的关联没有合并。我怎样才能解决这个问题?
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;
}
}
}
映射
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();
}
}
}