0
votes

First of all, please note I´ve been checking other questions like this: Unable to update the EntitySet - because it has a DefiningQuery and no <UpdateFunction> element exist

but none of them worked for me unfortunately

I am getting the following error message, that happens when there is no primary key on the table:

DbUpdateException was unhandled

Additional information: Unable to update the EntitySet 'Employee' because it has a DefiningQuery and no element exists in the element to support the current operation.

I am getting the error when executing:

...
    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
Does the id for employee have an identity set up? If so, are you providing the id in this situation and not letting the dB create it?theogjpeezy
@theogjpeezy Thanks for your attention. I think it doesn´t have any identity set up, I just created the entity and the table as I always do, but it is not working in this casestack man

1 Answers

0
votes

I fixed it by doing the following:

  • Edit XML code in .edmx model
  • List item
  • Remove< DefiningQuery >