【问题标题】:Entity framework model first timestamp实体框架模型第一个时间戳
【发布时间】:2012-03-23 18:24:50
【问题描述】:

我正在开发基于实体框架的应用程序。我正在使用模型优先的方法。我想处理并发问题。正如在许多文章中所写的那样,我将通过将 ConcurrencyMode 固定在一个时间戳字段上来做到这一点。目前我正面临这个问题 - 我无法添加时间戳类型的字段(列)。如何在模型中做到这一点?

这里写的:

http://social.msdn.microsoft.com/Forums/is/adodotnetentityframework/thread/1ed8d1e4-9d78-4593-9b10-33e033837af8\

我尝试安装 Entity Designer Database Generation Power Pack,但我仍然看不到从模型生成时间戳的可能性(我什至尝试在 edmx 文件中手动设置它,但我仍然没有在生成的数据库中收到时间戳 fcolumn )。

请帮忙。

【问题讨论】:

    标签: .net entity-framework timestamp ef-model-first


    【解决方案1】:

    我认为数据库类型时间戳映射到 EF 中的二进制属性类型。

    我的模型的时间戳列是二进制类型,长度为 8,固定长度为 true,StoreGenratedPattern 为 Computed。

    编辑:实际上不可能不更改 t4 模板,如下所述:Entity Framework timestamp Generate Database issue

    【讨论】:

      【解决方案2】:

      EF 6.1,我有这个:

      public partial class DepartmentEFEntity
      {
      
          Guid DepartmentUUID { get; set; }
      
          public byte[] TheVersionProperty { get; set; }
      }
      

      然后:

              modelBuilder.Entity<DepartmentEFEntity>().Property(o => o.TheVersionProperty).HasColumnType("timestamp").HasDatabaseGeneratedOption(DatabaseGeneratedOption.Computed).IsRowVersion();
      

      当我编写表格时,我得到了这个:

      CREATE TABLE [dbo].[Department](
          [DepartmentUUID] [uniqueidentifier] NOT NULL,
          [TheVersionProperty] [timestamp] NOT NULL
          )
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-22
        • 2010-09-22
        相关资源
        最近更新 更多