无法更新实体,因为它具有definedQuery且没有<插入函数> </insertfunction>

时间:2014-03-20 17:33:44

标签: c# asp.net asp.net-mvc

使用实体框架尝试创建新产品。为了让它工作,我添加了虚拟值,4,4,4 bla,123等,但它仍然不允许我添加一个新的记录,它试图保存它给我错误:

Unable to update the EntitySet 'HandHeld_Product' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation.

我不知道为什么我之前用不同的产品和列表等多次这样做了......但从未见过这个错误请指教?

using (EPOSEntities1 db = new EPOSEntities1())
            {
                foreach (Product product in Products)
                {
                    HandHeld_Product HH = new HandHeld_Product();
                    HH.Id = 4;// product.Id;
                    HH.ServerProductId = 4;// product.ServerProductId;
                    HH.Name = "bla";// product.Name;//should be description
                    HH.ItemBarcode = "123";// product.ItemBarcode;
                    HH.CaseBarcode = "123";// product.CaseBarcode;
                    HH.NumInItem = 123;// product.NumInItem;
                    HH.NumInCase = 123;// product.NumInCase;
                    HH.IsWeighableOnKegScales = true;// product.IsWeighableOnKegScales;
                    HH.IsWeighableOnSpiritScales = true;// product.IsWeighableOnSpiritScales;
                    HH.EmptyWeight = 123;// product.EmptyWeight;
                    HH.FullWeight = 123;//product.FullWeight;

                    db.AddToHandHeld_Product(HH);
                    db.SaveChanges();
                }
            }

1 个答案:

答案 0 :(得分:1)

可能是您的数据库表没有主键。