我在使用数据注释时缺少一些东西。数据注释不会创建一对多的对象引用
这是我的第一类
[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”); –
好吧,你去了 - 它应该是属性名称,例如“商店,物品,历史” –