0

I'm getting the following exception when I try to update a table using Linq To Sql:

El valor de miembro 'IdSeccionNovedad' de un objeto de tipo 'Novedad' ha cambiado. No se puede modificar un miembro que define la identidad del objeto. Agregue un nuevo objeto con una nueva identidad y elimine el existente.

wich first sentence can be translated to something like:

Cannot modify member which defines object identity

The table is this:

CREATE TABLE [dbo].[Novedades](
    [IdNovedad] [int] NOT NULL,
    [IdSeccionNovedad] [int] NOT NULL,
    [Antetitulo] [varchar](250) NULL,
    [Titulo] [varchar](250) NOT NULL,
    [Sumario] [varchar](max) NULL,
    [Cuerpo] [varchar](max) NULL,
    [FechaPublicacion] [smalldatetime] NOT NULL,
    [Activo] [bit] NOT NULL,
 CONSTRAINT [PK_Novedades] PRIMARY KEY CLUSTERED 
(
    [IdNovedad] ASC,
    [IdSeccionNovedad] ASC
)

I know I can solve this using an stored procedure, but how can I solve this using Linq To Sql?

2 Answers 2

1

Composite Keys are ... well outright ugly and in my opinion an indication of bad database design. However, since you seem to want to go this route ... the table design in itself is not enough for anyone to figure out why this isn't working. In theory you should not be having any issues as long as your values are valid. Can you please provide the code you're using to update?

Regards.

1
  • Yah, I agree. I pretty much ALWAYS set up my db with all tables having a ROWID numeric, identity column. And use that as my primary key, and then add a unique index if there is a logical multi-field "key" that needs to be enforced.
    – eidylon
    Sep 2, 2009 at 23:29
0

What I do is to use an stored procedure to update the table, because I can't undone the database design.

For future designs, I will use tables with only 1 key.

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.