我正试图通过我在这里找到的基本内容进行流畅的映射:
http://wiki.fluentnhibernate.org/Fluent_configuration
他们明确地添加这样的每个类型:
ISessionFactory localFactory =
Fluently.Configure()
.Database( ObjectFactory.GetInstance<SybaseConfiguration>().GetSybaseDialect( "BLAH" ) )
.Mappings( m =>
{
m.HbmMappings
.AddFromAssemblyOf<StudTestEO>();
m.FluentMappings
.AddFromAssemblyOf<StudTestEO>()
.AddFromAssemblyOf<StudTestEOMap>();
} )
.BuildSessionFactory(); .BuildSessionFactory();
并尝试能够获取程序集,获取它的类型列表并将其传递给它 而是
有点像这样
string FullEoAssemblyFName = webAccessHdl.GetMapPath(EoAssemblyFName);
string FullMapAssemblyFName = webAccessHdl.GetMapPath(MapAssemblyFName);
string FullConfigFileName = webAccessHdl.GetMapPath("~/" + NHibernateConfigFileName);
if (!File.Exists(FullEoAssemblyFName))
throw new Exception("GetFactoryByConfigFile, EoAssemblyFName does not exist>" + FullEoAssemblyFName + "<");
if (!File.Exists(FullMapAssemblyFName))
throw new Exception("GetFactoryByConfigFile, MapAssemblyFName does not exist>" + FullMapAssemblyFName + "<");
if (!File.Exists(FullConfigFileName))
throw new Exception("GetFactoryByConfigFile, ConfigFile does not exist>" + FullConfigFileName + "<");
Configuration configuration = new Configuration();
Assembly EoAssembly = Assembly.LoadFrom(webAccessHdl.GetMapPath(EoAssemblyFName));
Assembly MapAssembly = Assembly.LoadFrom(webAccessHdl.GetMapPath(MapAssemblyFName));
Type[] EoType = EoAssembly.GetTypes();
Type[] MapType = MapAssembly.GetTypes();
ISessionFactory localFactory =
fluent.Mappings(
m =>
{
// how do i add all the types from type array here?
m.FluentMappings.Add(MapAssembly).AddFromAssembly(EoAssembly);
}
)
.BuildSessionFactory();
让它通用而不是显式地加载类型..
有没有人这样做,或者看到我应该看的文章的任何好链接?
谢谢,
电子 -
答案 0 :(得分:0)
config.Mappings(m => m
.FluentMappings.AddFromAssemblyOf<StudTest>());
这将添加包含StudTest的程序集中的所有映射;通常我只有一个包含项目映射的程序集,这样就足够了。