Cannot update identity column 'Id'

I have a table that has an identity field named Id. This field is used for partitioning and is not the key of the table. I have another Int64 field called OrgId which is the primary key.

When I try and do an update on this table it fails with the message: Cannot update identity column 'Id'

I guess my question is why? Can you have an identity column on a table that does not form part of the key?

Check the property in your model. If there is a [Key] attribute or the property in declared as Key in the context Fluent API Entity Framework will unable to update this property.

There is no [Key] attribute on my Id column.

image

Hmm.. there is however database generated identity (auto increment). Database generated properties cannot be updated as well.

I have a requirement for a non key integer identity field. Along with an Int64 primary key. I need both.

Please create the table below. You will be able to insert but not update.

Here is the script. Please try and do an update using radzen.

CREATE TABLE [dbo].[Tests](
[Id] [int] IDENTITY(1,1) NOT NULL,
[TestId] [bigint] NOT NULL,
[Name] varchar NOT NULL,
CONSTRAINT [PK_Tests] PRIMARY KEY CLUSTERED
(
[TestId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

I'm afraid that Entity Framework cannot update such field. This is not related to Radzen.

So you can't have a non key identity field?

I'll repeat myself for third time. This field is database generated and cannot be updated using UPDATE statement by Entity Framework.

But I am not updating it.

Just FYI. This is my exact problem. I am going to try and make another plan.

Try to add [NotMapped] attribute to this property. You will need to add the model file to application ignore list.

This worked ... thank you!

I apologize if my explanation was unclear.