使用FluentNhibernate的SchemaExport

epi*_*tka 1 nhibernate fluent-nhibernate schemaexport

这段代码有什么问题吗?我没有得到任何生成,也没有抛出异常.

  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));
        }
Run Code Online (Sandbox Code Playgroud)

mhe*_*xon 6

这取决于你想做什么.例如,如果你在内存数据库中使用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>());
    }
Run Code Online (Sandbox Code Playgroud)

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