“无效的对象名称”在流畅的nhibernate配置中出错

时间:2013-09-18 17:29:21

标签: nhibernate fluent-nhibernate

我在我的应用程序中使用流畅的nhibernate,我也使用sql server 2012.这是我的配置:

public class SessionFactory
    {
        private static ISessionFactory _sessionFactory;

        public static string ConnectionString
        {
            get { return ConfigurationManager.ConnectionStrings["ECommerceConnectionString"].ToString(); }
        }

        private static void Initialize()
        {
            var config = Fluently.Configure().Database(
                MsSqlConfiguration
                    .MsSql2008
                    .ConnectionString(ConnectionString).ShowSql().Dialect<MsSql2012Dialect>());
            _sessionFactory = config.Mappings(m => m.FluentMappings.AddFromAssemblyOf<ContactMapping>()).BuildSessionFactory();
        }

        private static ISessionFactory GetSessionFactory()
        {
            if (_sessionFactory == null)
                Initialize();

            return _sessionFactory;
        }

        private static ISession GetNewSession()
        {
            return GetSessionFactory().OpenSession();
        }

        public static ISession GetCurrentSession()
        {
            var sessionStorageContainer = SessionStorageFactory.GetStorageContainer();

            var currentSession = sessionStorageContainer.GetCurrentSession();

            if (currentSession == null)
            {
                currentSession = GetNewSession();
                sessionStorageContainer.Store(currentSession);
            }

            return currentSession;
        }
    }

虽然我正在使用MsSql2012Dialect但我仍然遇到sql server兼容性错误,我该怎么办呢?

1 个答案:

答案 0 :(得分:0)

你应该真的使用

 Fluently.Configure()
            .Database(
                MsSqlConfiguration
                .MsSql2012
                .ConnectionString(conString)
                .ShowSql)

能够流利地为我工作

错误“无效的对象名称”通常引用一个SQL异常,例如表不存在或类似的东西......完整的堆栈跟踪/错误消息会有所帮助。