4

我创建了一个 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)
);

我的 EF Fluent API 如下所示:

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

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

        }
    }

我的班级看起来像这样:

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

有人可以告诉我如何在课堂上定义 RowVersion 吗?

4

2 回答 2

3

这对我有用 - 我正在使用 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; }
}

映射:

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

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

PS:我的数据库列的数据类型是时间戳(我使用的是 SQL Server 2005)

于 2013-03-07T14:49:22.330 回答
2

我想这是

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; }
}
于 2013-03-07T14:43:08.007 回答