Deprecated feature 'INSERT NULL into TIMESTAMP columns' is not supported in this version of SQL Server

StackOverflow https://stackoverflow.com/questions/21989924

سؤال

I have a web API that uses Entity Framework Code First. Patient domain entity looks like:

public class Patient
{
    public string FirstName { get; private set; }
    public string LastName { get; private set; }
    ...
    public byte[] Version { get; private set; }                
}

Patient table is like:

CREATE TABLE [dbo].[Patient]
(
    [Id] INT NOT NULL PRIMARY KEY IDENTITY,
    [FirstName] NVARCHAR(100) NOT NULL,
    [LastName] NVARCHAR(100) NOT NULL,
    ...
    [Version] ROWVERSION NOT NULL,      
)

If I run this locally, patient entries are succesfully added to the database, so it works fine (SQL Server 2008 R2).

However, if I deploy to Azure and run it there, I get the exception:

An error occurred while updating the entries. See the inner exception for details. Deprecated feature 'INSERT NULL into TIMESTAMP columns' is not supported in this version of SQL Server.

If I remove the Version column from the table; and the Version property from the domain entity, it works also on Azure. If I remove it from the domain entity only (and leave it in the table), is also works!

What am I doing wrong?

هل كانت مفيدة؟

المحلول 3

It seems that Code First needs to know that the Version column is the concurrency token. If I add:

 modelBuilder.Entity<Patient>().ToTable("Patient").Property(p => p.Version).IsRowVersion().IsConcurrencyToken();

...it works.

نصائح أخرى

Decorate your code first version property with the timestamp attribute and all will be well.

http://msdn.microsoft.com/en-us/data/jj591583#TimeStamp

It happens because you got some nullable TIMESTAMP columns at your schema. It ill work at your local SQL Server 2008 but ill fail for SQL 2012 and is likely Azure ill run the newest SQL Version by default.

See this reference: Deprecated features in SQL 2012

You can try to set the compatibility level Setting compatibility level for SQL 2012

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top