tags:

views:

61

answers:

2

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?

+1  A: 

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.

Nissan Fan
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
A: 

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.

eKek0