I have a database table where one of the columns is an IDENTITY
column (not the primary key which is set manually). My EF Core model looks like this:
public class Model
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int Id { get; set; }
...Other fields...
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int AnotherId { get; set; }
}
Despite the annotation, when I do an update on the table I find that the SQL which is generated tries to update the IDENTITY
column:
UPDATE [Model] SET ... [AnotherId] = @p10 ...
WHERE [Id] = @p29;
SELECT @@ROWCOUNT;
This obviously fails, causing the an exception to be thrown. I am using Entity Core 2.0 and upgrading to 2.1 is currently not an option. Any ideas why the data annotation is being ignored?