Fluently.Configure without explicitly entering types
I'm trying to take my fluent mapping past the basic stuff that I've found here:
http://wiki.fluentnhibernate.org/Fluent_configuration
Where they explicitly add each type like this:
ISessionFactory localFactory =
Fluently.Configure()
.Database( ObjectFactory.GetInstance<SybaseConfiguration>().GetSybaseDialect( "BLAH" ) )
.Mappings( m =>
{
m.HbmMappings
.AddFromAssemblyOf<StudTestEO>();
m.FluentMappings
.AddFromAssemblyOf<StudTestEO>()
.AddFromAssemblyOf<StudTestEOMap>();
} )
.BuildSessionFactory(); .BuildSessionFactory();
and trying to be able to take the assembly, get a list of it's types and pass that in instead
kindf like this
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();
To get it to load the types generic开发者_C百科ly instead of explicitly..
has anyone done this, or see any good links to articles I should look at?
Thanks,
E-
config.Mappings(m => m
.FluentMappings.AddFromAssemblyOf<StudTest>());
This will add all mappings that are in the assembly containing StudTest; typically I only have one assembly containing mappings for a project so that's good enough.
精彩评论