【问题标题】:SchemaExport with FluentNhibernateSchemaExport 与 FluentNhibernate
【发布时间】:2009-09-22 02:01:55
【问题描述】:

这段代码有什么问题吗?我没有生成任何东西,也没有抛出异常。

  public static void ExportSchema()
        {
            Configuration cfg = LoadDefaultConfiguration();
            Fluently.Configure(cfg)
                .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.Load("dnnSphere.Meta")))
                .ExposeConfiguration(c => new SchemaExport(c).SetOutputFile("myDDL.sql").Execute(true,true,false));
        }

【问题讨论】:

    标签: nhibernate fluent-nhibernate schemaexport


    【解决方案1】:

    这取决于你想做什么。例如,如果您在内存数据库中使用 SQLite,除非我指定连接,否则我永远不会让它工作。这意味着我必须先打开一个会话并获得会话的连接。

        protected InMemoryFixture()
        {
    
            Configuration config = GetConfig();
            ISessionFactory sessionFactory = config.BuildSessionFactory();
    
    
            ISession session = _sessionFactory.OpenSession();
    
            new SchemaExport(_config).Execute(true, true, false, session.Connection, Console.Out);
    
        }
    
        private Configuration GetConfig()
        {
            return GetMappings()
                .Database(SQLiteConfiguration.Standard.InMemory)
                .BuildConfiguration();
        }
    
        private FluentConfiguration GetMappings()
        {
            return Fluently.Configure().Mappings(m => m.FluentMappings.AddFromAssemblyOf<NewsMap>());
        }
    

    然后还有SchemaExport(cfg).Create(true, true);当然还有 SchemaUpdate(cfg)。

    【讨论】:

    • 不,我使用的是 MSSQL 2005。问题是其中一列被命名为“Schema”。现在我解决了尝试 SQLLite 提供程序的问题,但出现错误:找不到 SQLite.NET 程序集中的 IDbCommand 和 IDbConnection 实现。确保程序集 SQLite.NET 位于应用程序目录或全局程序集缓存中。如果程序集在 GAC 中,请使用应用程序配置文件中的 元素指定程序集的全名。这就是你得到的吗?
    • 这是一个常见问题。首先需要将 SQLite 引用设置为本地复制(引用属性),然后您需要在运行之前构建项目。请注意,我主要使用 SQLite 进行测试,但它确实很漂亮! :) 在 MSSQL 2005 的情况下,尽管我使用 new SchemaExport(cfg).Create(true, true); 你应该可以接受。在这里创造成功。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-03
    • 1970-01-01
    • 2011-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多