View Ticket
Not logged in
Ticket UUID: 0af5daec0c77f150a6dbc2559180d8dfd66f51c7
Title: I can't update a weak entity because it has a DefiningQuery
Status: Closed Type: Incident
Severity: Important Priority: Medium
Subsystem: LINQ Resolution: Not_A_Bug
Last Modified: 2014-06-03 15:48:09
Version Found In:
User Comments:
anonymous added on 2014-06-03 07:10:22:
In my dataBase (SQLite) I have this table:

•Ficheros(IDFichero, Nombre...)
•FicherosSubtitulos(IDFichero, IDIdioma)

IDFichero in the Ficheros table it's an autoincremet and in the 
 FicherosSubtitulos it's primary key but not autonumeric, it's the same 
 ID that has Ficheros that is set when I create a new file. It's a weak 

The EF does not create the entity for FicherosSubtitulos, instead, create a propierty navigacion in Ficheros called Idiomas.

Well, if I try to create a new FicherosSubtitulos, I do the following:
miDBContext.Entry<Idiomas>(myFichero.Idiomas).State = System.Data.EntityState.Unchanged;

Then EF know that it has to create a new record in the table FicherosSubtitulos.

When I want to delete a record in FicherosSubtitulos, I use this code:
myFicheros.Idiomas = null;

EF knows that has to delete the record in the FicherosSubtitulos.

However, when I try to update the language, I try this:
myFichero.Idiomas = myNewIdioma;

But in this case I get this exception:
Unable to update the EntitySet - because it has a DefiningQuery and no element exists in the element to support the current operation.

How can I update the language in one record in my FicherosSubtitulos table?

I have read that the problem could be taht I don't set a primary key in my table in the dataBase, but the DLL is this:
CREATE TABLE [FicherosSubtitulos] (
  [IDIdioma] INTEGER NOT NULL CONSTRAINT [FK_FicherosSubtitulos_IDIdioma] REFERENCES [Idiomas]([IDIdioma]));

CREATE INDEX [IX_FicherosSubtitulos_IDIdioma] ON [FicherosSubtitulos] ([IDIdioma]);


anonymous added on 2014-06-03 07:22:58:
If I open the edmx model with the XML editor and search for "DefiningQuery" I don't get any result, so I don't have any definigQuery in my model, so the error that says that I have a definingQuery it's not very accurate.

mistachkin added on 2014-06-03 15:48:09:
Perhaps try the solution seen here: