我在使用數據註釋時缺少一些東西。數據註釋不會創建一對多的對象引用
這是我的第一類
[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; }
}
這是我第二類
[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; }
}
當我運行加載遷移,它正確地創建數據庫,但是當我試圖訪問PriceFeed。歷史它給我一個錯誤
{"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'."
我一直使用API Fluent並由我自己鍵入E碼像
.Entity<Student>()
.HasRequired<Standard>(s => s.Standard)
.WithMany(s => s.Students)
.HasForeignKey(s => s.StdId);
但現在我使用的數據說明,當我產生遷移,也不會創建「withmany」像上面。
我在做什麼錯?
異常消息來自某些查詢(帶有'Include'),您沒有顯示。 –
我正在使用存儲庫模式並調用包含歷史記錄表的pricerepository,就像這個PriceRepository.Get(x => x.Id == priceId,null,「Store,Item,PriceFeed__History」); –
好吧,你去了 - 它應該是屬性名稱,例如「商店,物品,歷史」 –