Free mapping - entities and class maps in different assemblies

When using a free configuration to specify smooth mappings, such as:

.Mappings(m => m.FluentMappings.AddFromAssembly(typeof(UserMapping).Assembly))

I am currently receiving the error message "NHibernate.MappingException: No persister for".

Is there a problem that my objects and my ClassMaps are in different assemblies? Suppose AddFromAssembly is interested in an assembly that contains class maps, not entities? (this is what I assumed)

Thanks!

UPDATE:

Sorry for not responding very quickly - I had to travel unexpectedly after setting up the award.

Anyway, thanks for the answers. I looked through them and updated my code to use AddFromAssemblyOf instead of AddFromAssembly, but still getting the same error. Maybe I'm doing something stupid. Here is the complete code for the factory session that I am using:

public class NHibernateHelper
    {
        private static ISessionFactory _sessionFactory;
        private static ISessionFactory SessionFactory
        {
            get
            {
                if (_sessionFactory == null)
                {
                    var mysqlConfig = FluentNHibernate.Cfg.Db.MySQLConfiguration
                        .Standard
                        .ConnectionString("CONNECTION STRING OMITTED")
                        .UseOuterJoin()
                        .ProxyFactoryFactory("NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle");

                    _sessionFactory = FluentNHibernate.Cfg.Fluently.Configure()
                                        .Database(mysqlConfig)
                                        .Mappings(m => m.FluentMappings.AddFromAssemblyOf<User>())
                                        .BuildSessionFactory();


                }

                return _sessionFactory;
            }
        }

        public static ISession OpenSession()
        {
            return SessionFactory.OpenSession();
        }
    }

I get this exception when trying to run a test on nunit, which uses the repository using this session mechanism:

NHibernate.MappingException: no persister for: xxxx.Model.Entities.User

thanks

PS: I tried using both in AddFromAssemblyOf (); A project with mapping definitions (DataAccess) has a link to a project with entities (Model).

+3
source share
4 answers

Fluent NHibernate ? 1.0. , SVN.

http://fluent-nhibernate.googlecode.com/svn/trunk/

, , , , , "" .

.Mappings(m => m.FluentMappings.AddFromAssemblyOf<User>())

, , AddFromAssemblyOf, . , . . - POCO, , , - .

.Mappings(m => m.AutoMappings
                .Add(AutoMap.AssemblyOf<MyNamespace.Entities.MyClass>()
                .Where(type => type.Namespace == "MyNamespace.Entities")

Where , .

+5

, ClassMaps ?

, ClassMap Entities

:

m.FluentMappings.AddFromAssemblyOf<UserMapping>()

,

+4

, , Yassir.

Fluent NHibernate Wiki AddFromAssemblyOf , , - . FNH :

 m.FluentMappings
  .AddFromAssemblyOf<YourEntity>(); 

, , , User, :

 m.FluentMappings
  .AddFromAssemblyOf<User>();

, .

+1

? ?

, 1

public static ISessionFactory GetSessionFactory()
    {
        //Old way, uses HBM files only
        //return (new Configuration()).Configure().BuildSessionFactory(); //requies the XMl file.

        //get database settings.
        Configuration cfg = new Configuration();//.Configure();

        ft = Fluently.Configure(cfg);

        //DbConnection by fluent
        ft.Database
            (
            MsSqlConfiguration
                .MsSql2005
                .ConnectionString(c => c
                   .Server(".\\SqlExpress")
                   .Database("NhibTest")
                   .TrustedConnection()
                )
                .ShowSql()
                .UseReflectionOptimizer()
            );

        //set up the proxy engine
        //cfg.Properties.Add("proxyfactory.factory_class", "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle");

        //get mapping files.
        ft.Mappings(m =>
             {
                 //set up the mapping locations
                 m.FluentMappings.AddFromAssemblyOf<PersonMap>();//.ExportTo("C:\\mappingfiles");
                 //m.Apply(cfg);
             });

        //return the SessionFactory
        return ft.BuildSessionFactory();
    }

  • project.Data < - Dao ( , )
  • project.Core < - POCO
  • project.UI

, Fluent NHibernate NHibernate

, S # arp Architectures, ,

NhibernateSession < - function: private static ISessionFactory CreateSessionFactoryFor

,

+1

Source: https://habr.com/ru/post/1716828/


All Articles