2013-10-02 48 views
0

Iam試圖生成數據庫的表,但不生成表。 我做了這樣的映射:如何用Fluent配置數據庫表?

using Domain.Entidades; 
using FluentNHibernate.Cfg; 
using FluentNHibernate.Cfg.Db; 
using NHibernate.Tool.hbm2ddl; 
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 

namespace Domain.Infraestrutura 
{ 
    public class Conexao 
    { 
     public static void CriarTabelasBanco() 
     { 

      FluentConfiguration configuration = Fluently.Configure() 
       .Database(MsSqlConfiguration.MsSql2008.ConnectionString(x => x.FromConnectionStringWithKey("psConnection")).ShowSql()) 
       .ExposeConfiguration(cfg => new SchemaExport(cfg).Create(true, true)) 
       .Mappings(x => x.FluentMappings.AddFromAssemblyOf<Pessoa>()); 

      configuration.BuildSessionFactory(); 
     } 
    } 
} 

回答

0

第一添加您的映射,然後調用ExposeConfiguration,否則映射不知道你叫的SchemaExport點的配置。

除此之外,SchemaExport默默地失敗,所以如果有任何錯誤,它不會拋出和異常,而是你可以看看SchemaExport實例的例外列表,因此你必須稍微構造一個調用不同。