My code is returning the following error:
The property 'cartID' cannot be configured as a navigation property. The property must be a valid entity type and the property should have a non-abstract getter and setter. For collection properties the type must implement ICollection where T is a valid entity type.
My model is below:
[Table("ShoppingCarts")]
public class ShoppingCart
{
[Key]
public string cartID { get; set; }
public virtual ICollection<ShoppingCartItem> CartItems { get; set; }
public DateTime? DateCreated { get; set; }
public Guid UserID { get; set; }
}
[Table("ShoppingCartItems")]
public class ShoppingCartItem
{
private string cartDisplayImg;
[Key]
[Display(Name = "Cart Item ID#")]
public int cartItemID { get; set; }
[Display(Name = "Cart ID")]
[ForeignKey("cartID")]
public string cartID { get; set; }
[Required]
public string itemTitle { get; set; }
public int listingID { get; set; }
public int sellerID { get; set; }
[Required]
public string sellerSKU { get; set; }
[Required]
public int Quantity { get; set; }
public string itemType { get; set; }
public string condition { get; set; }
[Required]
public decimal Price { get; set; }
public string Make { get; set; }
public string Model { get; set; }
public string displayImgPath
{
get {
cartDisplayImg = "http://www.example.com/Images/Phones/" + Make + "-" + Model + "-1.jpg";
return cartDisplayImg;
}
}
public decimal lineTotal
{
get {
decimal cartLineTotal = Price * Quantity;
return cartLineTotal;
}
}
}
public class ShopingCartContext : DbContext
{
public ShopingCartContext()
: base("PHONEOUTLET_DBConnectionString")
{
Database.SetInitializer<ShopingCartContext>(new CreateDatabaseIfNotExists<ShopingCartContext>());
}
public DbSet<ShoppingCart> ShoppingCart { get; set; }
public DbSet<ShoppingCartItem> ShoppingCartItems { get; set; }
}