Fluent NHibernate和PostgreSQL,SchemaMetadataUpdater.QuoteTableAndColumns-System.NotSupportedException:不支持指定的方法

Fluent NHibernate和PostgreSQL,SchemaMetadataUpdater.QuoteTableAndColumns-System.NotSupportedException:不支持指定的方法,nhibernate,postgresql,fluent-nhibernate,Nhibernate,Postgresql,Fluent Nhibernate,我在PostgreSQL中使用fluentnhibernate。Fluentnhibernate是最新版本。PosrgreSQL版本是8.4。 创建ISessionFactory的我的代码: public static ISessionFactory CreateSessionFactory() { string connectionString = ConfigurationManager.ConnectionStrings["PostgreConnectionString"]

我在PostgreSQL中使用fluentnhibernate。Fluentnhibernate是最新版本。PosrgreSQL版本是8.4。 创建ISessionFactory的我的代码:

public static ISessionFactory CreateSessionFactory()
{
        string connectionString = ConfigurationManager.ConnectionStrings["PostgreConnectionString"].ConnectionString;
        IPersistenceConfigurer config = PostgreSQLConfiguration.PostgreSQL82.ConnectionString(connectionString);

        FluentConfiguration configuration = Fluently
            .Configure()
            .Database(config)
            .Mappings(m =>
                m.FluentMappings.Add(typeof(ResourceMap))                                    
                                .Add(typeof(TaskMap))
                                .Add(typeof(PluginMap)));
        var nhibConfig = configuration.BuildConfiguration();
        SchemaMetadataUpdater.QuoteTableAndColumns(nhibConfig);
        return configuration.BuildSessionFactory();
}
当我在SchemaMetadataUpdater.QuoteTableAndColumns(nhibConfig)行执行代码时;抛出错误:System.NotSupportedException:不支持指定的方法。请帮帮我!我非常需要解决这个问题。 致以最诚挚的问候

试试这个:

public static ISessionFactory CreateSessionFactory()
{
        string connectionString = ConfigurationManager.ConnectionStrings["PostgreConnectionString"].ConnectionString;
        IPersistenceConfigurer config = PostgreSQLConfiguration.PostgreSQL82.ConnectionString(connectionString);

        FluentConfiguration configuration = Fluently
            .Configure()
            .Database(config)
            .Mappings(m =>
                m.FluentMappings.Add(typeof(ResourceMap))                                    
                                .Add(typeof(TaskMap))
                                .Add(typeof(PluginMap)));
        configuration.ExposeConfiguration(x => x.SetProperty("hbm2ddl.keywords", "auto-quote"));
        return configuration.BuildSessionFactory();
}
  • SchemaMetadataUpdater.QuoteTableAndColumns(nhibConfig)
  • ExposeConfiguration(x=>x.SetProperty(“hbm2ddl.keywords”,“自动报价”) 我试过以上两种方法。最新的Fluent NHibernate(5f7adcd)和最新的postgresql 8.4不适合我。这两个人很可能是流利的NHibernate的哑巴。如果你使用 NHibernate和HBM没有流利的语言,这对你很有用

    为了明确要求Fluent NHibernate为表和列生成带引号的标识符, 我在Fluent NHibernate源代码中修补了两个文件,以强制它为postgresql工作。 (如果其他数据库不需要相同的版本)

    命名空间:
    FluentNHibernate.MappingModel.Output

  • XmlClassWriter.cs的表名中添加“Quote”

    if (classMapping.HasValue(x => x.TableName))
      classElement.WithAtt("table", new System.Text.StringBuilder().Append("\"").Append(classMapping.TableName).Append("\"").ToString());
    
  • XmlColumnWriter.cs的列名中添加“Quote”

    if (columnMapping.HasValue(x => x.Name))
      element.WithAtt("name", new System.Text.StringBuilder().Append("\"").Append(columnMapping.Name).Append("\"").ToString());
    
  • 到目前为止,这很有魅力。来源于
    并使用上述更新构建您自己的。

    创建自定义命名约定,覆盖列名约定以包含引号

    var fluentConfig = Fluently.Configure(new     Configuration().SetNamingStrategy(PostgreNamingStragegy.Instance))
    
    internal class PostgreNamingStragegy: INamingStrategy
        {
        private static readonly INamingStrategy ImprovedNamingStrategy = NHibernate.Cfg.ImprovedNamingStrategy.Instance;
    
        private static PostgreNamingStragegy_postgreNamingStrategy;
        public static INamingStrategy Instance
        {
            get { return _postgreNamingStrategy?? (_postgreNamingStrategy= new PostgreNamingStragegy()); }
        }
    
        protected PostgreNamingStragegy()
        {
        }
    
        public string ClassToTableName(string className)
        {
            return ImprovedNamingStrategy.ClassToTableName(className);
        }
    
        public string ColumnName(string columnName)
        {
            return "\"" + columnName + "\"";
        }
    
        public string LogicalColumnName(string columnName, string propertyName)
        {
            return ImprovedNamingStrategy.LogicalColumnName(columnName, propertyName);
        }
    
        public string PropertyToColumnName(string propertyName)
        {
            return ImprovedNamingStrategy.PropertyToColumnName(propertyName);
        }
    
        public string PropertyToTableName(string className, string propertyName)
        {
            return ImprovedNamingStrategy.PropertyToTableName(className, propertyName);
        }
    
        public string TableName(string tableName)
        {
            return ImprovedNamingStrategy.TableName(tableName);
        }
    }
    
    PostgreSQL将“Quoted”视为区分大小写,非Quoted标识符不区分大小写,但全部折叠为小写,这意味着如果您不希望Fluent NHibernate为您生成区分大小写的“Quoted”查询,您可以将所有表和列重命名为小写名称,这会让你下次看到它们时感到奇怪冷却此(
    configuration.ExposeConfiguration…
    )也适用于MS SQL(以防万一)。