Я использую Fluent и NHibernate V2.4 в своем веб-приложении.
Из-за моего дизайна у меня есть файлы сопоставления в нескольких сборках.
Однако, когда я пытаюсь добавить в сборку вторую сборку (см. Код ниже), я получаю сообщение о том, что класс (единственный в этой сборке во второй точке) уже сопоставлен (само собой разумеется есть один класс отображения на класс).
Вы видите, где я иду не так?
Ошибка:
Duplicate class/entity mapping
NHibernate.Cfg.Mappings.AddClass(PersistentClass persistentClass) +181
NHibernate.Cfg.XmlHbmBinding.JoinedSubclassBinder.HandleJoinedSubclass(PersistentClass model, XmlNode subnode, IDictionary`2 inheritedMetas) +1834
NHibernate.Cfg.XmlHbmBinding.ClassBinder.PropertiesFromXML(XmlNode node, PersistentClass model, IDictionary`2 inheritedMetas, UniqueKey uniqueKey, Boolean mutable, Boolean nullable, Boolean naturalId) +1911
NHibernate.Cfg.XmlHbmBinding.ClassBinder.PropertiesFromXML(XmlNode node, PersistentClass model, IDictionary`2 inheritedMetas) +64
NHibernate.Cfg.XmlHbmBinding.RootClassBinder.Bind(XmlNode node, HbmClass classSchema, IDictionary`2 inheritedMetas) +1214
NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddRootClasses(XmlNode parentNode, IDictionary`2 inheritedMetas) +270
NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.Bind(XmlNode node) +162
NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc) +262
[MappingException: Could not compile the mapping document: (XmlDocument)]
NHibernate.Cfg.Configuration.LogAndThrow(Exception exception) +136
NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc) +387
NHibernate.Cfg.Configuration.ProcessMappingsQueue() +74
NHibernate.Cfg.Configuration.AddDocumentThroughQueue(NamedXmlDocument document) +64
NHibernate.Cfg.Configuration.AddXmlReader(XmlReader hbmReader, String name) +94
NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name) +158
NHibernate.Cfg.Configuration.AddDocument(XmlDocument doc, String name) +323
NHibernate.Cfg.Configuration.AddDocument(XmlDocument doc) +72
FluentNHibernate.PersistenceModel.Configure(Configuration cfg) +751
FluentNHibernate.Cfg.FluentMappingsContainer.Apply(Configuration cfg) +472
FluentNHibernate.Cfg.MappingConfiguration.Apply(Configuration cfg) +332
FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() +108
[FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
]
FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() +325
Liath.Surveys.Dao.NHibernate.BurrowFluentConfigurator.Config(IPersistenceUnitCfg puCfg, Configuration nhCfg) in C:\Subversion\Surveys\Source\Liath.Surveys.Dao.NHibernate\BurrowFluentConfigurator.cs:49
NHibernate.Burrow.Impl.PersistenceUnit..ctor(IPersistenceUnitCfg cfg, IConfigurator configurator) +148
NHibernate.Burrow.Impl.PersistenceUnitRepo.Initialize(IBurrowConfig configuration) +212
NHibernate.Burrow.Impl.FrameworkEnvironment.Start() +185
NHibernate.Burrow.Impl.FrameworkEnvironment.ReConfig(IConfigurator configurator) +159
NHibernate.Burrow.Impl.FrameworkEnvironment..ctor() +55
NHibernate.Burrow.Impl.FrameworkEnvironment..cctor() +53
[TypeInitializationException: The type initializer for 'NHibernate.Burrow.Impl.FrameworkEnvironment' threw an exception.]
NHibernate.Burrow.Impl.FrameworkEnvironment.get_Instance() +60
NHibernate.Burrow.Impl.WorkSpace.get_Current() +50
NHibernate.Burrow.BurrowFramework.get_WorkSpaceIsReady() +59
NHibernate.Burrow.BurrowFramework.CloseWorkSpace() +62
NHibernate.Burrow.WebUtil.WebUtilHTTPModule.CloseContext(Object sender, EventArgs e) +103
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +148
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
Вот код для моего конфигуратора:
public void Config(IPersistenceUnitCfg puCfg, Configuration nhCfg)
{
try
{
string[] assemblies =
{
"AssemblyA",
"AssemblyB"
}; // TODO: push down into config
FluentConfiguration fluentCfg = Fluently.Configure(nhCfg);
fluentCfg = fluentCfg.Database(FluentNHibernate.Cfg.Db.MsSqlConfiguration.MsSql2005
.ConnectionString(@"Server=localhost\SQLEXPRESS;initial catalog=MyDatabase;Integrated Security=SSPI"));
foreach (string assemblyName in assemblies)
{
fluentCfg = fluentCfg.Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.Load(assemblyName)));
}
fluentCfg.BuildConfiguration();
}
catch (Exception ex)
{
s_log.Error("There was an error configuring NHibernate", ex);
throw;
}
}