【问题标题】:"Invalid object name"Error in fluent nhibernate configuration“无效的对象名称”流畅的休眠配置中的错误
【发布时间】:2013-09-29 20:25:52
【问题描述】:

我在我的应用程序中使用 fluent 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 兼容性错误,请问我该如何解决?

【问题讨论】:

  • 你能发布完整的例外吗? “无效的对象名称”看起来太笼统了

标签: nhibernate fluent-nhibernate


【解决方案1】:

你真的应该使用

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

流利地为我工作

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-06-23
    • 2015-03-29
    • 2011-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多