using fluent-nhibernate and traditionally hbm.xml

2019-02-27 16:37发布

问题:

So far I used this code to configure a session factory:

        Configuration configuration = new Configuration();
        configuration.Configure();
        SessionFactory = configuration.BuildSessionFactory();

Now I added some fluentNhibernate mapping classes, and used this code to configure:

    Configuration configuration = new Configuration();
    configuration.Configure();
    SessionFactory = configuration.BuildSessionFactory();


    SessionFactory = Fluently.Configure(configuration).Mappings(m =>
    {
        m.FluentMappings.AddFromAssemblyOf<AttachmentLocaionMap>();
        m.FluentMappings.AddFromAssemblyOf<AttachmentTypeMap>();
        m.FluentMappings.AddFromAssemblyOf<AttachmentMap>();
     }).BuildSessionFactory();

But I guess it overrided the old xml mapping? Now I want to add then to the already existing exmbeded resources xml-based mapping

How do I do this?

i saw this blog, but i don't want to add

configuration.AddXmlFile( "Mappings/Insurance.hbm.xml" ); or configuration.AddAssembly(...);

for each existing xml (as up till now I dodn't do it for each ebmbeded resource xml)

回答1:

    SessionFactory = Fluently.Configure(configuration).Mappings(m =>
{
    m.FluentMappings.AddFromAssemblyOf<AttachmentLocaionMap>();
    m.FluentMappings.AddFromAssemblyOf<AttachmentTypeMap>();
    m.FluentMappings.AddFromAssemblyOf<AttachmentMap>();
    m.HbmMappings.AddFromAssemblyOf<SomeTypeFromYourAssemblyWithHbmMappings>()
 }).BuildSessionFactory();