문제

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 i.e. 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>())
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top