0

我编写了以下 C# 代码:

        abcEntities entities = new abcEntities();            
        abc_Lids_New newUserEntry = new abc_Lids_New()
        {
            Lid = lid,
            FName = fname,
            LName = lname,
            Phone = phone,
        };
        newUserEntry.abc_class_Assignments_New = new System.Data.Objects.DataClasses.EntityCollection<abc_class_Assignments_New>();
        foreach (string classId in classIds)
        {
            newUserEntry.abc_class_Assignments_New.Add(new abc_class_Assignments_New()
            {
                Lid = lid,
                classID = classId
            });
        }
        entities.abc_Lids_New.AddObject(newUserEntry);
        entities.SaveChanges();

该代码应该在 abc_Lids_New 中添加代表新用户的新行。该代码还应该在 abc_class_assignments_new 中添加与用户的盖子和一些类 ID 相对应的行。

但是,我收到一个错误:Unable to update the EntitySet 'UCV_TF_Assignments_New' because it has a DefiningQuery and no <InsertFunction> element exists in the <ModificationFunctionMapping> element to support the current operation.

直到最近,我只使用实体框架和存储过程,所以这对我来说是新事物。

4

1 回答 1

0

您的EntitySet“'UCV_TF_Assignments_New”要么基于View(在这种情况下,您必须创建InsertFunction(存储过程)),要么它缺少主键(在这种情况下,添加一个)。

于 2012-08-10T15:22:09.203 回答