EntityFramework One-To-Many fK?

馋奶兔 提交于 2020-01-06 08:23:06

问题


     BasketItem duplicateBasketItem = (from ph in storeDB.BasketItems
                                         where ph.sellerSKU == newItem.sellerSKU
                                         select ph).SingleOrDefault();

{"Invalid column name 'BasketID'."}

My Classes:

 public class Basket
{
    [Key]
    public string BasketID { get; set; }

    public virtual IList<BasketItem> BasketItems { get; set; }
    public int? Count { get; set; }
    public System.DateTime DateCreated { get; set; }
    public Guid UserID { get; set; }
}


public class BasketItem
{
    [Key]
    public int BasketItemID { get; set; }

    public virtual string BasketID { get; set; }
    [Required]
    public int sellerID { get; set; }
    [Required]
    public string sellerSKU { get; set; }
    [Required]
    public int Quantity { get; set; }
    [Required]
    public decimal Price { get; set; }

}

From the research i have done so far, the error is being cause due to relationships not being mapped properly. How would I map the relationship using modelbuilder

Each basket can(optional) contain many basketitems

Each BasketItem has a BaskedID(FK) to map back to the individual Basket.

来源:https://stackoverflow.com/questions/24640197/entityframework-one-to-many-fk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!