我正在尝试更新CART
。当我在搜索它时,它失败了。它使用了GUID
,因为用户没有登录。我不知道是否必须重新更新DBEntities
?不确定。
我收到此错误:The specified type member 'CartId' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.
由于
ShoppingCart.cs
namespace Tp1WebStore3.Models
{
public partial class ShoppingCart
{
Tp1WebStoreDBEntities db = new Tp1WebStoreDBEntities();
string ShoppingCartId { get; set; }
public const string CartSessionKey = "CartId";
public static ShoppingCart GetCart(HttpContextBase context)
{
var cart = new ShoppingCart();
cart.ShoppingCartId = cart.GetCartId(context);
return cart;
}
// Helper method to simplify shopping cart calls
public static ShoppingCart GetCart(Controller controller)
{
return GetCart(controller.HttpContext);
}
public void AddToCart(Produit produit)
{
// Get the matching cart and album instances
var cartItem = db.Paniers.SingleOrDefault(
c => c.CartId == ShoppingCartId &&
c.ProduitId == produit.ProduitId); <== the error happen here
Panier.cs
namespace Tp1WebStore3.Models
{
using System;
using System.Collections.Generic;
public partial class Panier
{
public int PanierId { get; set; }
public string CartId { get; set; }
public int ProduitId { get; set; }
public int Quantite { get; set; }
public decimal Prix { get; set; }
public System.DateTime DateCree { get; set; }
public virtual Produit Produit { get; set; }
}
}
produit.cs
namespace Tp1WebStore3.Models
{
using System;
using System.Collections.Generic;
public partial class Produit
{
public Produit()
{
this.Paniers = new HashSet<Panier>();
}
public int ProduitId { get; set; }
public int CategorieId { get; set; }
public string Description { get; set; }
public int Quantite { get; set; }
public decimal Prix { get; set; }
public virtual Categorie Categorie { get; set; }
public virtual ICollection<Panier> Paniers { get; set; }
}
}
答案 0 :(得分:0)
如果您更改了数据库中的内容,则必须更新数据模型。右键单击实体图所在的.edmx文件,然后单击“从db更新模型”