문제

레거시 DB에 기존 ASP.NET 멤버십 및 역할 테이블이 있으며 유창한 NHibernate를 가진 새로운 엔티티에 매핑하고 있습니다.

또한 fluent 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