首先,请注意我一直在检查这样的其他问题:Unable to update the EntitySet - because it has a DefiningQuery and no <UpdateFunction> element exist
但不幸的是,他们都没有为我工作
我收到以下错误消息, that happens when there is no primary key on the table :
未处理DbUpdateException附加信息:无法更新EntitySet'Employee',因为它具有DefiningQuery,并且元素中不存在支持当前操作的元素 .
执行时我收到错误:
...
ctx.Employee.Add(employee);
ctx.SaveChanges();
...
However, my table has the primary key defined :
CREATE TABLE [dbo].[Employee] (
[Id] INT NOT NULL,
[name] VARCHAR (50) NOT NULL,
[surname] VARCHAR (50) NOT NULL,
[password] VARCHAR (50) NOT NULL,
[dni] VARCHAR (50) NOT NULL,
[phone] VARCHAR (50) NOT NULL,
[salary] VARCHAR (50) NOT NULL,
[email] VARCHAR (50) NOT NULL,
[address] VARCHAR (50) NOT NULL,
[postcode] VARCHAR (50) NOT NULL,
[city] VARCHAR (50) NOT NULL,
[province] VARCHAR (50) NOT NULL,
[admin] BIT NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
1 回答
我通过执行以下操作修复了它:
在.edmx模型中编辑XML代码
列出项目
删除
< DefiningQuery >