유창한 nhibernate를 사용하여 테이블 인덱스를 생성합니다
-
03-07-2019 - |
문제
유창한 nhibernate를 사용하여 나머지 데이터베이스 스키마와 함께 테이블 인덱스를 생성 할 수 있습니까? 자동화 된 빌드 프로세스를 통해 전체 데이터베이스 DDL을 생성하고 싶습니다.
해결책
보다 최근의 유창한 nhibernate 버전에서 Index()
사용하기보다는이 작업을 수행하는 방법 SetAttribute
(더 이상 존재하지 않는) :
Map(x => x.Prop1).Index("idx__Prop1");
다른 팁
열의 인덱스를 의미합니까?
당신은 당신의 수동으로 그것을 할 수 있습니다 ClassMap<...>
추가로 파일 .SetAttribute("index", "nameOfMyIndex")
, 예 : 그렇게 :
Map(c => c.FirstName).SetAttribute("index", "idx__firstname");
또는 automapper의 속성 기능을 사용하여 다음과 같이 할 수 있습니다.
지속성 모델을 만든 후 :
{
var model = new AutoPersistenceModel
{
(...)
}
model.Conventions.ForAttribute<IndexedAttribute>(ApplyIndex);
}
void ApplyIndex(IndexedAttribute attr, IProperty info)
{
info.SetAttribute("index", "idx__" + info.Property.Name");
}
그런 다음이를 엔터티에게 수행하십시오.
[Indexed]
public virtual string FirstName { get; set; }
나는 후자를 좋아한다. IS는 도메인 모델에 무관심하지는 않지만 여전히 일어나고있는 일에 대해 매우 효과적이고 명확한 것 사이의 좋은 타협입니다.
Mookid의 대답은 훌륭하고 많은 도움이되었지만, 계속 진화하는 유창한 Nhibernate API가 바뀌 었습니다.
따라서 지금 mookid 샘플을 작성하는 올바른 방법은 다음과 같습니다.
//...
model.ConventionDiscovery.Setup(s =>
{
s.Add<IndexedPropertyConvention>();
//other conventions to add...
});
IndexEdPropertyConvention은 다음과 같습니다.
public class IndexedPropertyConvention : AttributePropertyConvention<IndexedAttribute>
{
protected override void Apply(IndexedAttribute attribute, IProperty target)
{
target.SetAttribute("index", "idx__" + target.Property.Name);
}
}
인덱스] 속성은 지금 같은 방식으로 작동합니다.
제휴하지 않습니다 StackOverflow