내 모델 : EF-코드 첫번째 복합 형
public class Country
{
public int CountryId { get; set; }
public string Name { get; set; }
public virtual ICollection<User> Users { get; set; }
}
public class Location
{
public string Address { get; set; }
public virtual int CountryId { get; set; }
public virtual Country Country { get; set; }
}
public class User{
protected User()
{
Location = new Location();
}
public int UserId { get; set; }
public Location Location { get; set; }
}
데이터베이스를 생성, 내가 얻을 :
One or more validation errors were detected during model generation:
System.Data.Edm.EdmEntityType: : EntityType 'Location' has no key defined. Define the key for this EntityType.
System.Data.Edm.EdmEntitySet: EntityType: EntitySet �Locations� is based on type �Location� that has no keys defined.
이 어떻게 복잡한 유형의 내부 탐색 속성을해야합니까? 국가 탐색 속성을 제거하면 올바르게 작동합니다.
그러나'Location' 클래스의'CountryID' 정수는 어떨까요? 외래 키 제약 조건을 만들 수 있습니까? (나는 비슷한 문제가있어 작동하지 못합니다) –
@Isak : 불가능하지 않습니다. 데이터베이스에서 FK를 원한다면 데이터베이스에서 직접해야하지만 EF는이를 반영하지 않습니다. –
이것이 지원되지 않는다는 사실은 MSDN의 복잡한 형식 설명에서 직접 언급됩니다. http://msdn.microsoft.com/en-us/library/bb738472.aspx –