EF 6의 enum을 FK로 사용하기
-
23-12-2019 - |
문제
코드 첫 번째 응용 프로그램에서 열거 형을 외래 키로 사용하고 싶습니다.enums는 int로 저장되므로 Enum 속성에서 [ForeameKey] 속성을 사용할 수 있지만이 예외가 발생했습니다.
The types of all properties in the Dependent Role of a referential constraint
must be the same as the corresponding property types in the Principal Role
.
여기에 내가하려는 것의 예가 있습니다 :
public enum UserType
{
Administrator = 1,
Member = 2
}
public class User
{
public int UserId { get; set; }
public string Login { get; set; }
[ForeignKey("TypeDetails")]
public UserType Type { get; set;}
public virtual MasterType TypeDetails { get; set; }
}
public class MasterType
{
public int MasterTypeId { get; set; }
public string Description { get; set; }
...
}
.
유창한 API 또는 마이그레이션을 통해이 또는 비슷한 것을 수행 할 수 있습니까?
감사합니다
해결책
여기에 내가 만들었던 것입니다 : https://www.nuget.org/패키지 / ef-enum-lookup
Lookup 테이블을 자동으로 빌드하고 enum이 사용되는 fk를 추가하는 Seed
(초기화 기 및 / 또는 마이그레이션)에서 호출 할 수있는 방법을 제공하는 NuGet 패키지입니다. 사용 정보 .
즐기십시오 :-) 그리고 당신이 당신을 위해 작동하는지 (또는 그 밖의 중요한 누구도)
제휴하지 않습니다 StackOverflow