无法从程序集中添加映射
我正在努力在项目中使用 NHibernate 设置 Fluent 映射。通过复制一个工作项目 - 我最终仍然没有映射,随后出现异常 FluentConfigurationException:创建 SessionFactory 时使用了无效或不完整的配置。 更多详细信息。
检查 PotentialReasons 集合和InnerException
以了解 调试。对 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; }
}
编辑
最内层异常的堆栈跟踪(一些单词)是瑞典语,但你会明白的):
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文件夹)\r\n vid FluentNHibernate.Cfg.FluentMappingsContainer.Apply(配置cfg)\r\n vid FluentNHibernate.Cfg.MappingConfiguration.Apply(配置cfg)\r\n vid FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()
I'm struggling with setting up Fluent mappings with NHibernate in a project. With a working project to copy from - I still end up with no mappings and subsequently the exception FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
No clues in either PotentialReasons or InnerException as I gather though...
I've used the suggested method calls from the Fluent documentation and only split them across lines to be able to debug. The call to BuildSessionFactory
fails, and no xml files are exported in the previous call.
What am I missing? Any ideas or suggestions? Getting more gray hair by the minute...
All these classes live in the same assembly, in different namespaces.
SessionFactoryCreator class: (part of)
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;
Mapping class:
public class AlarmData : ClassMap<AlarmTemp>
{
public AlarmData()
{
Table("PublishOperationMessage");
Id(s => s.OperationMessageId, "OperationMessageId");
}
}
DTO class:
public class AlarmTemp : Base
{
public virtual int OperationMessageId { get; private set; }
}
EDIT
Stacktrace of the innermost exception (some words are in swedish, but you'll get it):
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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
AlarmTemp 中必须有一个默认构造函数。
You have to have a default constructor in AlarmTemp.
好吧,这太奇怪了。我用谷歌搜索了堆栈跟踪消息并最终到达此页面:
http://geekswithblogs .net/rupreet/archive/2005/12/21/63740.aspx
因此,我绝望地想做任何事情,所以我退出了VS,删除bin文件夹,重新启动VS并构建。你猜怎么着——现在可以了。 :-)
Ok, this is so weird. I googled the stacktrace message and ended up on this page:
http://geekswithblogs.net/rupreet/archive/2005/12/21/63740.aspx
So, desperate to do anything, I quit VS, deleted the bin folders, restarted VS and built. Guess what - it works now. :-)