首页 文章

从Fluent Nhibernate模式生成中排除一些表

提问于
浏览
3

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

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

是否可以说Fluent Nhibernate从某一代表中排除?

3 回答

  • 4

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

    public class DoNotAutoPersistAttribute : Attribute
    {
    }
    

    然后在AutoPersistenceModelGenerator中,您可以在AddEntityAssembly的Where子句中检查此属性 .

  • 0

    _425720_在你的ClassMap中 .

  • 0

    我用属性约定管理了这个:

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

相关问题