我正在努力在项目中使用NHibernate设置Fluent映射。有一个可以复制的工作项目 - 我最终没有映射,随后是例外FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
我收集的潜在理由或InnerException都没有线索......
我已经使用了Fluent文档中建议的方法调用,并且只能跨行拆分它们才能进行调试。对BuildSessionFactory
的调用失败,并且在上一次调用中没有导出xml文件。
我错过了什么?任何想法或建议?一分钟变得更白发......
所有这些类都位于同一个程序集中,位于不同的名称空间中。
SessionFactoryCreator类:(部分)
var a = Fluently.Configure();
var cs = MsSqlConfiguration.MsSql2005
.ConnectionString(c => c.FromConnectionStringWithKey("AlarmDataDb"));
var b = a.Database(cs);
var d = b.Mappings(x => x.FluentMappings.AddFromAssemblyOf<Mappings.AlarmData>()
.ExportTo(@"C:\"));
var e = d.BuildSessionFactory();
_sessionFactory = e;
映射类:
public class AlarmData : ClassMap<AlarmTemp>
{
public AlarmData()
{
Table("PublishOperationMessage");
Id(s => s.OperationMessageId, "OperationMessageId");
}
}
DTO课程:
public class AlarmTemp : Base
{
public virtual int OperationMessageId { get; private set; }
}
修改
最内层异常的Stacktrace(有些单词是瑞典语,但你会得到它):
vid FluentNHibernate.MappingModel.TypeReference..ctor(Type type)\r\n vid FluentNHibernate.Mapping.IdentityPart.FluentNHibernate.Mapping.Providers.IIdentityMappingProvider.GetIdentityMapping()\r\n vid FluentNHibernate.Mapping.ClassMap1.FluentNHibernate.IMappingProvider.GetClassMapping()\r\n vid FluentNHibernate.PersistenceModel.BuildSeparateMappings(Action1 add)\r\n vid FluentNHibernate.PersistenceModel.BuildMappings()\r\n vid FluentNHibernate.PersistenceModel.EnsureMappingsBuilt()\r\n vid FluentNHibernate.PersistenceModel.WriteMappingsTo(Func2 writerBuilder, Boolean shouldDispose)\r\n vid FluentNHibernate.PersistenceModel.WriteMappingsTo(String folder)\r\n vid FluentNHibernate.Cfg.FluentMappingsContainer.Apply(Configuration cfg)\r\n vid FluentNHibernate.Cfg.MappingConfiguration.Apply(Configuration cfg)\r\n vid FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()
答案 0 :(得分:0)
您必须在 AlarmTemp 中拥有默认构造函数。
答案 1 :(得分:0)
好的,这太奇怪了。我用谷歌搜索了栈跟踪消息,最后在这个页面上:
http://geekswithblogs.net/rupreet/archive/2005/12/21/63740.aspx
所以,不顾一切地做任何事情,我退出VS,删除了bin文件夹,重新启动VS并构建。猜猜看 - 它现在有效。 : - )