나는 내 응용 프로그램에 대한2 cols로 클래스를 참조하는 방법 2 cols로 구성된 클래스의 CompositeId FluentNhibernate의 CompositeId?
public class BaseMap<T> : ClassMap<T>
을 만들려고 해요. 내가 원하는
CompositeId()
.KeyProperty(x => x.Id)
.KeyProperty(x => ((ILocalizedEntity)x).Language);
또 다른 것은 하나 개의 지역화 된 클래스가 다른 지역화 된 클래스를 참조 할 수 있습니다 : 그것은 그들의 기본 키가 모두 아이디 & 언어해야 지역화 된 엔티티를 지원해야한다. 내가했던
은 다음 (많은 연구 후에, 이것은 내가 가진 모든 임) : 이것은 나에게 삽입을 시도 IndexOutOfRange 예외를 준
public new ManyToOnePart<TOther> References<TOther>(Expression<Func<T, TOther>> memberExpression) where TOther : BaseEntity
{
if (typeof(ILocalizedEntity).IsAssignableFrom(typeof(TOther)))
{
return base.References(memberExpression)
.Columns("CategoryId")
.Columns("Language");
}
return base.References(memberExpression);
}
, 이유였습니다 "언어"속성 두 번 매핑하지만, DB 만 1 언어 열이 있었다, 그래서 나는이 한되었다
public new ManyToOnePart<TOther> References<TOther>(Expression<Func<T, TOther>> memberExpression) where TOther : BaseEntity
{
if (typeof(ILocalizedEntity).IsAssignableFrom(typeof(TOther)))
{
return base.References(memberExpression)
.Columns("CategoryId")
.Columns("Language")
.Not.Update()
.Not.Insert();
}
return base.References(memberExpression);
}
IndexOutOfRange 문제를 해결하지만, 내가 원하는 것을 성취하지 않았다 어느. 그것은 Not.Insert()와 Not.Update()를 지정했기 때문에 항상 "CategoryId"컬럼에 NULL을 삽입하기 때문에 그렇지 않습니다!
이제 "CategoryId"가 매핑되었지만 "언어"가 매핑되지 않기를 바란다. 이미 매핑 되었기 때문에 CompositeId (기본 키)의 일부이기 때문이다. 그러나 중 하나가 행운 - 그것은 단지 "언어"가 아닌 "카테고리 ID"를 삽입하거나 업데이트하지 않습니다 Whishing
public new ManyToOnePart<TOther> References<TOther>(Expression<Func<T, TOther>> memberExpression) where TOther : BaseEntity
{
if (typeof(ILocalizedEntity).IsAssignableFrom(typeof(TOther)))
{
return base.References(memberExpression)
.Columns("CategoryId")
.Nullable()
.Columns("Language")
.Not.Update()
.Not.Insert();
}
return base.References(memberExpression);
}
:
그래서 나는이에 시도했다. 는 또한 먼저 PK에서 언어를 만들려고했습니다 CompositeId()
.KeyProperty(x => ((ILocalizedEntity)x).Language)
.KeyProperty(x => x.Id);
그리고에 대한 참조를 변경 :
return base.References(memberExpression)
.Columns("Language")
.Not.Update()
.Not.Insert()
.Columns("CategoryId")
.Nullable();
그러나 여전히 "Not.Insert()"와 "하지 않음 .Update() "가"언어 "&"CategoryId "에 모두 영향을줍니다.
I는 다음과 같이 "참조"호출하기 전에 "카테고리 ID를"매핑 시도 :
Map(memberExpression, "Language");
return base.References(memberExpression)
.......
그러나 실패했습니다.
누구나 2 열이있는 클래스에서 2 열의 CompositeId를 참조하는 방법이 있습니다. 하나의 열이 기본 키와 외래 키에 공통적 인 경우 CompositeId?
가능한 한 compositeIds를 피하십시오.다음은 또한 중복을 피할 수 있습니다. http://stackoverflow.com/a/5431842/671619 – Firo
그래도 사용하고 싶다면 왜 그렇게 복잡해야합니까? 구조적으로 프로그램과 DB에서 무엇이 옳은지 생각해 보면 복합 ID가 때로는 최상의 선택입니다 ... 그렇지 않습니까? –