데이터 주석을 사용할 때 뭔가가 누락되었습니다.데이터 주석이 일대 다 객체 참조를 생성하지 않음
이 내 첫 수업
[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"를 작성하지 않습니다.
내가 뭘 잘못하고 있니?
표시되지 않은 일부 쿼리 ('포함'포함)에서 예외 메시지가 표시됩니다. –
저장소 패턴을 사용하고이 PriceRepository.Get (x => x.Id == priceId, null, "Store, Item, PriceFeed__History")와 같이 히스토리 테이블을 포함한 pricerepository를 호출하고 있습니다. –
음, 거기 가세요 - 속성 이름이어야합니다 (예 : "상점, 아이템, 역사" –