2009-11-10 14 views
1

성 액티브에 일대일 협회와 함께 주위를 연주하는 동안 나는 다음과 같은 문제를 우연히 발견 이 경우에는 -userprofile). 나는 이것이 모범 사례는 아닐 수도 있다는 것을 이미 알았지 만, 잠시 그 ​​것을 무시하자. 나는 아직도 어떤 일이 벌어지고 있는지 이해하려고 노력하고있다.성 액티브 :</p> <p>내가 일대일 관계를 모델링하기 위해 노력하고있어 (사용자 : 일대일

[ActiveRecord] 
public class TestUser : ActiveRecordBase<TestUser> 
{ 
    [PrimaryKey(PrimaryKeyType.GuidComb)] 
    public Guid Id { get; set; } 


} 

[ActiveRecord] 
public class TestUserProfile : ActiveRecordBase<TestUserProfile> 
{ 
    [PrimaryKey(PrimaryKeyType.GuidComb)] 
    public Guid Id { get; set; } 

    [OneToOne(Cascade = CascadeEnum.All, Fetch = FetchEnum.Join)] 
    public TestUser User { get; set; } 
} 

나는 다음과 같은 코드가 데이터베이스에 동일한 ID를 산출 프로필을 가진 사용자를 저장 기대 :

[Test] 
    public void save_profile_saves_user() 
    { 
     var profile = new TestUserProfile 
     { 
      User = new TestUser() 
     }; 

     profile.Save(); 

    } 

실제 결과는 그러나 두 객체가 다른 키와 함께 저장된다는 것입니다. 나는 무엇인가 놓치고 있냐??

답변

3

나는 직접 답변을 찾았습니다. ...

더 철저하게 문서를 읽는

[ActiveRecord] 
public class TestUserProfile : ActiveRecordBase<TestUserProfile> 
{ 
    [PrimaryKey(PrimaryKeyType.Foreign)] 
    public Guid Id { get; set; } 

    [OneToOne(Cascade = CascadeEnum.All, Fetch = FetchEnum.Join)] 
    public TestUser User { get; set; } 

} 

돌아 가기 : OneToOne가 ​​정의 관계의 측면의 PrimaryKeyType는 PrimaryKeyType.Foreign의 기본 키가 있어야합니다

관련 문제