Ticket Hash: | 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: | 1.0.91.0 | |||
User Comments: | ||||
anonymous added on 2014-06-03 07:10:22:
(text/x-fossil-plain)
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 relationship. 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] ( [IDFicheros] INTEGER NOT NULL PRIMARY KEY CONSTRAINT [FK_FicherosSubtitulos_IDFichero] REFERENCES [Ficheros]([IDFichero]) ON DELETE CASCADE ON UPDATE CASCADE, [IDIdioma] INTEGER NOT NULL CONSTRAINT [FK_FicherosSubtitulos_IDIdioma] REFERENCES [Idiomas]([IDIdioma])); CREATE INDEX [IX_FicherosSubtitulos_IDIdioma] ON [FicherosSubtitulos] ([IDIdioma]); Thanks. anonymous added on 2014-06-03 07:22:58: (text/x-fossil-plain) 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: (text/x-fossil-plain) Perhaps try the solution seen here: [http://geekswithblogs.net/ranganh/archive/2010/05/31/unable-to-update-the-entityset-because-it-has-a-definingquery.aspx] |