Currently I am creating a project following 'MVC Music Store' tutorial, when come to create a view for "ShoppingCartViewModel", it always shows the error that tells me that there is no Key definied. The error message is: Entity type'ShoppingCartViewModel' has no key defined....
Here is the original code from the tutorial:
namespace MyMVStore.ViewModels
{
public class ShoppingCartViewModel
{
public List<Cart> CartItems { get; set; }
public decimal? CartTotal { get; set; }
}
}
Here is what I updated:
//[NotMapping]
namespace MyMVStore.ViewModels
{
public class ShoppingCartViewModel
{
[Key] //my code
public int Id { get; set; } // my code
public List<Cart> CartItems { get; set; }
public decimal? CartTotal { get; set; }
}
}
I put [Key] and Id to the model, seems not working. I also tried to add [Notmapping], it doesn't work either. The error massage still showing up when I tried to create the view for this model.