2017-12-15 16 views
1

나는 이것을 많은 주석에 유창하게 구사하는 방법을 이해하려고 노력하고있다. 난 그냥 열 순서를 나타내는 구문을 모르겠다.Fluent Api Column 순서 sytax

public class UserNotification 
    { 
    [key] 
    [Column(Order = 1)] 
    public string UserId { get; set;} 

    [key] 
    [Column(Order = 2)] 
    public int NotificationId {get; set;} 

    public ApplicationUser User{get; set;} 
    public Notification Notification {get; set;} 
    } 

나는 유창 API는 다음과 같이 알고 다음과 같이

protected override void OnModelCreating(ModelBuilder modelBuilder) 
{ 
    modelBuilder.Entity<UserNotification>() 
    .HasKey(n => new {n.UserId, n.NotificationId}); 

    // What about the Column Order? 
} 

답변

2

당신은 KeyColumn 데이터 주석을 읽을 수 있습니다

UserNotification을가있다 열쇠 consisti 사용자 ID가 NG는는 사용자 아이디 먼저 인 와 NotificationId 두번째 인 상태 열 NotificationId.

열의 순서 속성은 복합 기본 키의 맥락에서 제 등이 먼저되는 열을 결정하기 위해서만 사용된다, 즉.

유창함 API를 사용하면 HasKey 표현 내부의 키 열 및 순서를 모두 설명하기 때문에 것을 필요로하지 않는다 : 즉

modelBuilder.Entity<UserNotification>() 
    .HasKey(n => new { n.UserId, n.NotificationId }); 
//      ^  ^
//      first  second 

을, 당신은 정확하게, 더 이상의 조치가 필요하지 않았다.

+1

고마워요! 정말 대단합니다. 나는 빨리 배우고있다. – AllocSystems