配置FluentNHibernate、FluentMappings.AddFromAssembly;意义
该行
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Product>()
有什么作用?它会在派生自 ClassMap 的 Product 类的程序集中查找任何类吗?或者说背后的逻辑是什么?我可以将该程序集的任何随机类放在这里并期望它找到该程序集中的所有映射类吗?
private static ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(Properties.Settings.Default.FnhDbString)
.Cache(c => c
.UseQueryCache()).ShowSql())
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Product>()
.Conventions.Add(FluentNHibernate.Conventions.Helpers.DefaultLazy.Never()))
.BuildSessionFactory();
}
The line
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Product>()
What does it do? Will it look for any class in the assembly of the Product class that derives from the ClassMap ? Or what is the logic behind? Can I just put any random class of that assembly here and expect it to find all mapping classes in this assembly?
private static ISessionFactory CreateSessionFactory()
{
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(Properties.Settings.Default.FnhDbString)
.Cache(c => c
.UseQueryCache()).ShowSql())
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Product>()
.Conventions.Add(FluentNHibernate.Conventions.Helpers.DefaultLazy.Never()))
.BuildSessionFactory();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我一直认为,当您使用 AddFromAssemblyOf 时,Fluent 会尝试映射程序集中的每个类。
因此,您只需从包含 ClassMap 的程序集中添加一个类(任何一个)。
来自 Fluent wiki 的附加内容
I always thought that when you use
AddFromAssemblyOf
, fluent will try to map EVERY class in the assembly.Therefore you just need to add a class (any one) from an assembly that contains your ClassMap.
Additional from the fluent wiki