다른 클래스 안에 복잡한 클래스를 저장하려고합니다. TypeMask는 Entity 내부에 포함됩니다. TypeMask는 ToString 메서드를 오버로드하고 Entity를 저장하는 시간이 오면 문자열 형식의 Mask prop를 저장하고 필요할 때 Entity 클래스를 다시로드해야 할 때 automaticaly이 문자열을 TypeMask로 변환합니다 (TypeMask의 생성자는 string을 사용하여 TypeMask를 빌드 할 수 있음). 그래서 내가 과부하를 걸거나 내가 진짜로 상속 한 것에서 무엇을 얻었습니까?EF 복잡한 클래스를 저장하는 방법
public class Entity
{
private TypeMask _typeMask;
[Key]
public int Id { get; set; }
public string TypeMaskString { get; set; }
[NotMapped]
public TypeMask Mask
{
get
{
if (this._typeMask == null && !string.IsNullOrEmpty(TypeMaskString))
{
this._typeMaks = new TypeMask(this.TypeMaskString);
// Or some other way to create a TypeMask from string.
}
return this._typeMask;
}
set
{
this._typeMask = value;
this.TypeMaskString = value.ToString();
}
}
}
여기에서 염두에 두어야 할 몇 가지가 있습니다
public class Entity
{
[Key]
public int Id { get; set; }
public TypeMask Mask { get; private set; }
}