代码之家  ›  专栏  ›  技术社区  ›  Brian

从Fluent Nhibernate架构生成中排除一些表

  •  3
  • Brian  · 技术社区  · 16 年前

    我在遗留数据库中有一些现有的asp.net成员资格和角色表,我正在使用Fluent Nhibernate将它们映射到新实体。

    我还直接从Fluent Nhibernate生成模式,然后手动调整生成的sql脚本以排除现有表。

    3 回复  |  直到 16 年前
        1
  •  6
  •   James Gregory    16 年前

    SchemaAction.None() 在你的类地图上。

        2
  •  0
  •   dove    16 年前

    public class DoNotAutoPersistAttribute : Attribute
    {
    }
    

        3
  •  0
  •   jenson-button-event    14 年前

    我用属性+约定来管理它:

     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
       ...