4

I have created a SQL table and an EF Fluent mapping as follows:

CREATE TABLE [dbo].[Application] (
    [ApplicationId]   INT            IDENTITY (1, 1) NOT NULL,
    [Name] NVARCHAR (50) Not NULL,
    [DataVersion] ROWVERSION,
    CONSTRAINT [PK_dbo.Application] PRIMARY KEY CLUSTERED ([ApplicationId] ASC)
);

My EF Fluent API looks like this:

public class ApplicationConfiguration : EntityTypeConfiguration<Application>
    {
        public ApplicationConfiguration()
        {
            Property(a => a.Name)
                .IsRequired()
                .HasMaxLength(35);

            Property(p => p.RowVersion).IsRowVersion();

        }
    }

My Class looks like this:

public class Application
{
    public int ApplicationId { get; set; }
    public string Name { get; set; }
    public virtual ICollection<TestAccount> TestAccounts { get; set; }
    xxxxxxx
}

Can someone tell me how I can define the RowVersion in my class?

1
  • What version of EF are you using? Commented Mar 7, 2013 at 14:44

2 Answers 2

3

This works for me - I'm using EF4:

public class Application
{
    public int ApplicationId { get; set; }
    public string Name { get; set; }
    public virtual ICollection<TestAccount> TestAccounts { get; set; }

    public virtual byte[] RowVersion { get; set; }
}

Mapping:

public class ApplicationConfiguration : EntityTypeConfiguration<Application>
{
    public ApplicationConfiguration()
    {
        Property(a => a.Name)
            .IsRequired()
            .HasMaxLength(35);

        Property(p => p.RowVersion).HasColumnName("DataVersion").IsRowVersion();
    }
}

PS: The datatype of my database colum is timestamp (I'm using SQL Server 2005)

Sign up to request clarification or add additional context in comments.

Comments

2

I think it's

public class Application
{
    public int ApplicationId { get; set; }
    public string Name { get; set; }
    public virtual ICollection<TestAccount> TestAccounts { get; set; }
    public virtual byte[] DataVersion { get; set; }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.