C# Fluent NHibernate FluentMappings.AddFromAssemblyOf<> 问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/918157/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fluent NHibernate FluentMappings.AddFromAssemblyOf<> Issue
提问by Cody
A coworker and I were recently doing the backend for a small application using Fluent NHibernate. We wrote our entities, mapping files, persistence manager, but for some reason we couldn't export the database schema to anything.
我和一位同事最近正在使用 Fluent NHibernate 为一个小型应用程序做后端。我们编写了实体、映射文件、持久性管理器,但由于某种原因,我们无法将数据库模式导出到任何内容。
Through the debugger we discovered that the FluentMappings.AddFromAssemblyOf was returning 0 mappings, even though they are clearly there, and clearly correct. We tried everything we could think of, and ended up having to do add each mapping manually.
通过调试器,我们发现 FluentMappings.AddFromAssemblyOf 返回 0 映射,即使它们显然存在,并且显然是正确的。我们尝试了我们能想到的一切,最终不得不手动添加每个映射。
The following is the code that did not work:
以下是无效的代码:
return Fluently.Configure().Database(
MsSqlConfiguration.MsSql2005
.ConnectionString(c => c
.TrustedConnection()
.Server("localhost")
.Database("LDTT")))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<UserMap>())
.ExposeConfiguration(BuildSchema)
.BuildSessionFactory();
Whereas this code did work:
而这段代码确实有效:
return Fluently.Configure().Database(
MsSqlConfiguration.MsSql2005
.ConnectionString(c => c
.TrustedConnection()
.Server("localhost")
.Database("LDTT")))
.Mappings(m => m.FluentMappings.Add<ClientMap>())
.Mappings(m => m.FluentMappings.Add<ContactMap>())
.Mappings(m => m.FluentMappings.Add<DepartmentMap>())
.Mappings(m => m.FluentMappings.Add<DivisionMap>())
.Mappings(m => m.FluentMappings.Add<FileMap>())
.Mappings(m => m.FluentMappings.Add<FileTypeMap>())
.Mappings(m => m.FluentMappings.Add<RegionMap>())
.Mappings(m => m.FluentMappings.Add<TimeEntryMap>())
.Mappings(m => m.FluentMappings.Add<UserMap>())
.ExposeConfiguration(BuildSchema)
.BuildSessionFactory();
Does anyone know why this happens, and how to fix it?
有谁知道为什么会发生这种情况,以及如何解决?
采纳答案by Darin Dimitrov
Make UserMap a publictype.
使 UserMap 成为公共类型。