0

在使用助手处理剑道调度程序时,我无法AddObject(Entity)用于添加新实体。它显示错误 -

不包含“AddObject”的定义,也没有接受第一个参数的“AddObject”的扩展方法(缺少一些参考?)

public ActionResult Tasks_Create([DataSourceRequest]DataSourceRequest request, TaskViewModel task)
        {


            if (ModelState.IsValid)
            {
                using (var sampleDB = new EntitiesModel())
                {
                    //Task task_obj = new Task();

                    //Create a new Task entity and set its properties from the posted TaskViewModel
                    var entity = new Task
                    {
                        TaskID = task.TaskID,
                        Title = task.Title,
                        Start = Convert.ToString(task.Start),
                        End = Convert.ToString(task.End),
                        Description = task.Description,
                        RecurrenceRule = task.RecurrenceRule,
                        RecurrenceException = task.RecurrenceException,
                        RecurrenceID = Convert.ToString(task.RecurrenceID),
                        IsAllDay = Convert.ToString(task.IsAllDay),
                        OwnerID = Convert.ToString(task.OwnerID)
                    };


                    // Add the entity

                    sampleDB.Tasks.AddObject(entity);
                    // Insert the entity in the database
                    sampleDB.SaveChanges();
                    // Get the TaskID generated by the database
                    task.TaskID = entity.TaskID;
                }
            }
            // Return the inserted task. The scheduler needs the generated TaskID. Also return any validation errors.
            return Json(new[] { task }.ToDataSourceResult(request, ModelState));


        }
4

0 回答 0