开发者

How do I avoid Persistance and Mapping exceptions in NHibernate?

开发者 https://www.devze.com 2023-04-09 17:18 出处:网络
So I\'ve got the following code: try { var config = new Configuration(); config.Configure(); config.AddAssembly(typeof(Address).Assembly);

So I've got the following code:

try
{
    var config = new Configuration();
    config.Configure();
    config.AddAssembly(typeof(Address).Assembly);
    var factory = config.BuildSessionFactory();

    using (var session = factory.OpenSession())
    using (var xaction = session.BeginTransaction())
    {
        var address = createNewAddress();
        session.Save(address);
        xaction.Commit();
        var lastAddressID = address.AddressID;
    }
}

The problem is, I am using NHibernate t开发者_C百科o do some mapping, and when it hits the config.Configure() line, if I have the EmbeddeAsResource option set, it throws a "Can't compile mapper" exception. Weird, right?

So I switched to "Content", and that worked.

But then it got to session.Save(address) and threw a "No Persistance available" exception.

I've been working on this for a couple hours and my head is spinning. I would appreciate any help you can give!

Thanks!


When you set it to 'Content' - it is ignored by NHibernate, so it isn't loaded - which gives you no problems configuring the sessionfactory - and also gives you the 'persister missing' exception when you start using the (un)mapped entity.

So, we need to see your mapping - and the class that is mapped to help you further.

0

精彩评论

暂无评论...
验证码 换一张
取 消