2016-12-31 1 views
1

데이터 주석을 사용할 때 뭔가가 누락되었습니다.데이터 주석이 일대 다 객체 참조를 생성하지 않음

이 내 첫 수업

[Table("PriceFeed")] 
public class PriceFeed : History 
{ 
    public PriceFeed() 
    { 
     this.Votes = new List<PriceVote>(); 
     this.History = new List<PriceFeed__History>(); 
    } 

    [Key] 
    public long Id { get; set; } 

    [ForeignKey("Store")] 
    public long Store_Id { get; set; } 

    [ForeignKey("Item")] 
    public long Item_Id { get; set; } 

    [Required] 
    public decimal Price { get; set; } 

    public Store Store { get; set; } 

    public Item Item { get; set; } 

    public virtual ICollection<PriceFeed__History> History { get; set; } 

} 

입니다 그리고 내가 추가 마이그레이션을 실행하면이 내가 PriceFeed에 액세스 할 때 올바르게 데이터베이스를 만들지 만, 내 두 번째 클래스

[Table("PriceFeed__History")] 
public class PriceFeed__History : History 
{ 

    [Key] 
    public long Id { get; set; } 

    [ForeignKey("PriceFeed")] 
    public long PriceFeed_Id { get; set; } 

    [Required] 
    public decimal Price { get; set; } 

    public virtual PriceFeed PriceFeed { get; set; } 

} 

입니다. 내게 오류가 발생했습니다.

{"Message":"An error has occurred.","ExceptionMessage":"A specified Include path is not valid. The EntityType 'Verdinhas.Web.Contexts.PriceFeed' does not declare a navigation property with the name 'PriceFeed__History'." 

저는 항상 Fluent API로 작업하고 스스로 타이핑했습니다. 전자

.Entity<Student>() 
       .HasRequired<Standard>(s => s.Standard) 
       .WithMany(s => s.Students) 
       .HasForeignKey(s => s.StdId); 

과 같은 코드하지만 지금은 데이터 주석을 사용하고 있는데 내가 마이그레이션을 생성 할 때, 그것은 위처럼 "withmany"를 작성하지 않습니다.

내가 뭘 잘못하고 있니?

+0

표시되지 않은 일부 쿼리 ('포함'포함)에서 예외 메시지가 표시됩니다. –

+0

저장소 패턴을 사용하고이 PriceRepository.Get (x => x.Id == priceId, null, "Store, Item, PriceFeed__History")와 같이 히스토리 테이블을 포함한 pricerepository를 호출하고 있습니다. –

+1

음, 거기 가세요 - 속성 이름이어야합니다 (예 : "상점, 아이템, 역사" –

답변

1

문제는 모델에서 올바른 것으로 보이는 데이터 주석과 관련이 없습니다.

코멘트에서 언급 한 바와 같이

는, 예외가 stringInclude 방법을 사용하려고 코드로 인해 발생 " 'PriceFeed__History"- 당신은 관련 기업 유형를 지정해야한다고 생각하는 것 있지만, 사실은 당신이 필요 귀하의 경우 "기록"인 내비게이션 속성 이름을으로 지정하십시오.

+0

놀라운, 고마워요 –

+0

오신 것을 환영합니다, 다행 그것은 도움이 :) 새해 복 많이 받으세요! –