POINT 유형의 두 가지 속성을 포함하는 클래스 LINE이 있습니다. POINT를 구성 요소 속성으로하고 싶습니다. LINE에 POINT가 1 개만 포함되어 있으면 문제가되지 않지만 POINT가 2 개이므로 구별 할 필요가 있다고 생각합니다. 따라서 접두어 나 접미어를 열 이름에 적용 할 수 있습니다. ComponentProperty 태그의 PropertyName 특성을 사용했지만 X 및 Y 열 집합 하나만 내 LINE 테이블 내에 생성되었습니다.클래스의 동일한 유형의 Nhibernate 다중 구성 요소 속성
명확성을 위해 저의 목표는 Point1_X, Point1_Y, Point2_X 및 Point2_Y 열이있는 LINE 테이블을 갖는 것입니다.
당신은 내가 알아 낸 한편 내 매핑
[Class]
public class Line : EntityBase
{
[ComponentProperty(PropertyName = "Point1")]
public UiPoint Point1 { get; set; }
[ComponentProperty(PropertyName = "Point2")]
public UiPoint Point2 { get; set; }
//omitted the constructor
}
[Component]
public class UiPoint
{
[Property]
public double X { get; set; }
[Property]
public double Y { get; set; }
//omitted the constructor
}
을 볼 수 아래 나는 다음과 같은 XML 매핑 내 문제 해결 줘야 해, Nhibernate.Mapping.Attributes를 사용
<class name="Domain.WashProcessLine,Domain">
<id name="Id" />
<component name="Point1">
<property name="X" type="Double" column="Point1_X" />
<property name="Y" type="Double" column="Point1_Y" />
</component>
<component name="Point2">
<property name="X" type="Double" column="Point2_X" />
<property name="Y" type="Double" column="Point2_Y" />
</component>
</class>
에 대한 옵션이 발견되었습니다. https://www.hibernate.org/hib_docs/nhibernate/html/components.html
다음 태그를 지정하면 원하는 테이블 구조가 만들어 지지만 데이터베이스에서 속성을 가져올 때 캐스팅 예외 (UiPoint에서 IDictionary로)가 발생합니다. 그래서
나는 완전히이 아직 아니에요 :(
[Class]
public class Line : EntityBase
{
[DynamicComponent(1)]
[Property(2, Name = "X", Column = "Point1_X", TypeType = typeof(double))]
[Property(3, Name = "Y", Column = "Point1_Y", TypeType = typeof(double))]
public UiPoint Point1 { get; set; }
[DataMember]
[DynamicComponent(1)]
[Property(2, Name = "X", Column = "Point2_X", TypeType = typeof(double))]
[Property(3, Name = "Y", Column = "Point2_Y",TypeType=typeof(double))]
public UiPoint Point2 { get; set; }
}