2016-07-29 2 views
0

: 그러나하나 마시고/테이블이있는 경우 참조를 정의하는 방법 복합 기본 키, 당신은 주어진 예처럼 포항 강판의 외래 키 관계를 정의 할 수있는 문서 <a href="https://github.com/ServiceStack/ServiceStack.OrmLite" rel="nofollow">here</a>을 고려

public class Customer 
{ 
    [References(typeof(CustomerAddress))] 
    public int PrimaryAddressId { get; set; } 

    [Reference] 
    public CustomerAddress PrimaryAddress { get; set; } 
} 

을의 말을하자 내 CustomerAddress 그 poco 클래스는 실제로 이런 식으로 정의되어야합니다. 누군가가 이렇게 길고 오래 전에 테이블을 디자인하기로 결정했기 때문입니다.

public class CustomerAddress 
{ 
    [PrimaryKey] 
    public int Id_1 { get; set; } 

    [PrimaryKey] 
    public string Id_2 { get; set; } 
} 

어떻게 적절하게 정의 할 수 있습니다 내 [Reference]CustomerAddress에 정의 된 복합 키를 사용하여 Customer 클래스의 PrimaryAddress 속성?

답변

1

API를 사용할 수는 없지만 (SELECT은 여전히 ​​사용 가능) OrmLite limitations을 참조하십시오.

다른 프로젝트가 광산과 동일하기 때문에 기존 데이터베이스에서 동일한 문제가 발생했습니다. 수정할 수 없습니다. 그래서 기본 키를 삭제 한 다음 데이터베이스 (PK)에 새로운 Id 필드 (autoincrement)를 만들고 마지막으로 두 필드 모두에 고유 제한 조건 (NOT NULLABLE)을 만들었습니다.

이제 OrmLite를 사용하여 다른 프로젝트와의 호환성을 손상시키지 않고 올바르게 선택할 수 있습니다.