0

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)
);
2
  • 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? Commented May 20, 2016 at 11:59
  • @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 case
    – stack man
    Commented May 20, 2016 at 12:02

1 Answer 1

0

I fixed it by doing the following:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.