简体   繁体   中英

Fluent NHibernate mapping exception (no persister error)

I have the following code which gives me a mapping exception with no persister error:

var sessionFactory = Fluently.Configure()
    .Database(
        OracleClientConfiguration.Oracle10.ConnectionString(
            c => c.FromConnectionStringWithKey("Main.ConnectionString")))
    .Mappings(x => x.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()))
    .BuildSessionFactory();

using (var session = sessionFactory.OpenSession())
{
    using (var tx = session.BeginTransaction())
    {
        var card = new Card {CardType = "Test"};

        session.Save(card);

        tx.Commit();
    }
}

I have three projects in my solution: MainApplication , Entities and EntityMappings

MainApp has a reference to Entities and EntityMappings has a reference to Entities

I don't understand what I am doing wrong. Any ideas ?

EDIT:

The properties are public

The exact error message is : No persister for: TNT_DAL.EntityClasses.Card

Make sure that your entity and mapping classes are public . Properties for your entities ie database fields should be public virtual .

Also try specifying the assembly of a mapping class instead of using GetExecutingAssembly() , I do vaguely recall experiencing trouble with it when I tried setting up FNH for the first time.

.Mappings(x => x.FluentMappings.AddFromAssemblyOf<CardMap>())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM