내 질문은 다음과 유사이 하나한 최초의 EF 4.1 코드와 관련하여 하나
->Many to one configuration using EF 4.1 code first
"OnModelCreating"메서드를 재정의하고 수동 설정과 구글에 대한 몇 가지 유창 API 솔루션이 있습니다 외래 키 옵션 하지만 가능한 경우 데이터 주석이있는 솔루션을 선호합니다. 왜냐하면 코딩하는 동안 역 속성을 사용하고 싶습니다. TypeA 객체에는 TypeB 객체가 있습니다. 따라서 TypeB 객체에는 ParentTypeA 속성이 있어야합니다. 예 : 코드 처음에이 작업을 수행하는
public class User : IUser
{
[Key(), DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
[RegularExpression(@"[A-Za-z0-9_\-\.]{2,32}"), MinLength(2), MaxLength(32)]
[Required(AllowEmptyStrings = false)]
public string UserName { get; set; }
// other props ....
// ....
public virtual UserGallery Gallery { get; set; }
}
public class UserGallery : IUserGallery
{
[Key(), DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int UserGalleryId { get; set; }
// other props ....
// ....
public virtual User ParentUser { get; set; }
}
[Entity Framework 4 Code First (POCO)를 사용하여 일대일 관계를 선언하는 방법] (http://stackoverflow.com/questions/3622572/how-to-declare-one-to-one-relationship) -using-entity-framework-4-code-first-poco) –