开发者

No persister for entity using AutoMap in Fluent Nhibernate?

I'm trying to utilise FluentNHibernate with Automapping but am receiving the following error

  No persister for: nHibern开发者_如何学PythonateSpike.Entities.Route
    NHibernate.MappingException: No persister for: nHibernateSpike.Entities.Route

Here's the relevant stuff;

        var model = AutoMap.AssemblyOf<Route>().
            Where(t => t.Namespace == "nHibernateSpike.Entities");

        model.WriteMappingsTo(@"c:\hbm");

        var db = MsSqlConfiguration.MsSql2008
            .ConnectionString(c => c
            .Server("localhost")
            .Database("PTSIntegrationDB")
            .TrustedConnection()
            )
            .ShowSql();

        var sessionFactory = Fluently.Configure()
            .Database( db )
            //.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Route>())
            .Mappings(m => m.AutoMappings.Add(model))
            .BuildSessionFactory();

        return sessionFactory;

Entity

        namespace nHibernateSpike.Entities
        {
            public class Route
            {
                public virtual int Id { get; private set; }
                public virtual string Number { get; set; }
                public virtual string ConfirmationCategory { get; set; }

                public Route() { }

            }
        }

I'm pulling my hair out. Using the following ClassMap works;

        public class RouteMap: ClassMap<Route>
        {
            public RouteMap()
            {
                Table("Route");
                Id(c => c.Id);
                Map(c => c.Number);
                Map(c => c.ConfirmationCategory);
            }

        }

I have the opportunity to use AutoMap to drive the DB oon this project, and I'd like to use it - any clues?


I seem to recall there's an outstanding bug where calling WriteMappingsTo can prevent your mappings from being passed through to NHibernate, try removing that call and seeing what happens.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜