我有一个传统的DB一些现有的asp.net成员资格和角色表,我将它们映射与功能NHibernate新的实体。

我也直接从功能NHibernate生成的模式,然后我手动调整所生成的SQL脚本以排除现有的表。

是否有可能以连贯NHibernate说从一代某些表排除?

有帮助吗?

解决方案

SchemaAction.None()在类映射。

其他提示

另一个选择是创建一个属性,说

public class DoNotAutoPersistAttribute : Attribute
{
}

然后在AutoPersistenceModelGenerator,你可以检查AddEntityAssembly的Where子句中这个属性。

我与属性+约定管理这样的:

 public enum SchemaAction
  {
    None
  }


 [Serializable]
 [AttributeUsage(AttributeTargets.Class)]
 public class SchemaActionAttribute : Attribute
 {
    private readonly SchemaAction schemaAction = SchemaAction.None;

    public SchemaActionAttribute()
    {
    }

    public SchemaActionAttribute(SchemaAction schemaAction)
    {
      this.schemaAction = schemaAction;
    }

    public SchemaAction GetSchemaAction()
    {
      return schemaAction;
    }
  }

  /// <summary>
  ///  overrides the default action for entities when creating/updating the schema 
  ///  based on the class having a Schema attribute (<see cref="SchemaActionAttribute" />)
  /// </summary>
  public class SchemaActionConvention : IClassConvention
  {
    public void Apply(IClassInstance instance)
    {

      object[] attributes = instance.EntityType.GetCustomAttributes(true);
      foreach (object t in attributes)
      {
        if (t is SchemaActionAttribute)
        {
          var a = (SchemaActionAttribute) t;
          switch(a.GetSchemaAction())
          {
            case SchemaAction.None: 
              instance.SchemaAction.None();
              return;
            default: throw new ApplicationException("That schema action:" + a.GetSchemaAction().ToString() + " is not currently implemented.");
          }

        }
      }
    }
  }

...

 [SchemaAction(SchemaAction.None)]
 public class TextItem : Entity
   ...
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top