[英]How do I define RowVersion in a C# class when using SQL Server and Entity Framework
I have created a SQL table and an EF Fluent mapping as follows: 我创建了一个SQL表和一个EF Fluent映射,如下所示:
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: 我的EF Fluent API如下所示:
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? 有人能告诉我如何在班上定义RowVersion吗?
This works for me - I'm using EF4: 这对我有用 - 我正在使用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) PS:我的数据库列的数据类型是时间戳 (我使用的是SQL Server 2005)
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; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.