eKek0
eKek0

Reputation: 23319

How to update a table with a key composed by more than 1 field

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?

Upvotes: 0

Views: 322

Answers (2)

eKek0
eKek0

Reputation: 23319

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.

Upvotes: 0

Keith Adler
Keith Adler

Reputation: 21178

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.

Upvotes: 1

Related Questions