Nhibernate:数据库中可能不存在的映射列

Nhibernate:数据库中可能不存在的映射列,nhibernate,nhibernate-mapping,Nhibernate,Nhibernate Mapping,是否有一种方法可以映射数据库中可能存在或不存在的列,或者将其动态映射到列 您可以动态更改映射,但我认为没有办法映射可能存在或不存在的列。下面的示例是如果您使用的是fluent nhibernate,您可能会如何操作 var fluentConfiguration = Fluently.Configure(NHibernate.Cfg.Configuration().Configure()) .Mappings(m => m.FluentMappings

是否有一种方法可以映射数据库中可能存在或不存在的列,或者将其动态映射到列

您可以动态更改映射,但我认为没有办法映射可能存在或不存在的列。下面的示例是如果您使用的是fluent nhibernate,您可能会如何操作

var fluentConfiguration = Fluently.Configure(NHibernate.Cfg.Configuration().Configure())
      .Mappings(m =>
          m.FluentMappings
          .AddFromAssemblyOf<OrderMap>()
          .Conventions.AddFromAssemblyOf<PascalCaseColumnNameConvention>())
          .ProxyFactoryFactory("NHibernate.Bytecode.DefaultProxyFactoryFactory, NHibernate");

var config = fluentConfiguration.BuildConfiguration();

foreach(PersistentClass persistentClass in config.ClassMappings)
{
    //Check to see if there are any missing columns from this mapping.
    //If so remove the column from the mapping.

    //TODO: Query the database and catch errors related to missing columns
    //      If a column is missing remove it
}

var sessionFactory = config.BuildSessionFactory();
var fluentConfiguration=fluent.Configure(NHibernate.Cfg.Configuration().Configure())
.Mappings(m=>
m、 FluentMappings
.AddFromAssemblyOf()的
.Conventions.AddFromAssemblyOf())
.proxyFactory(“NHibernate.Bytecode.defaultproxyFactory,NHibernate”);
var config=fluentConfiguration.BuildConfiguration();
foreach(PersistentClass PersistentClass在config.ClassMappings中)
{
//检查此映射中是否缺少任何列。
//如果是,请从映射中删除该列。
//TODO:查询数据库并捕获与缺少列相关的错误
//如果缺少列,请将其删除
}
var sessionFactory=config.BuildSessionFactory();