实体框架时间戳生成数据库的问题[英] Entity Framework timestamp Generate Database issue

本文是小编为大家收集整理的关于实体框架时间戳生成数据库的问题的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我有EF 4.0的问题 我使用"时间戳"列创建实体.之后,我尝试生成数据库.

在SQL脚本中,列看起来像"二进制(8)",而不是时间戳.

如何解决它?

推荐答案

解决的问题:EF 4可以从EDMX Designer生成时间戳列. 解决方案很容易:

  1. 类型设置为二进制.
  2. 设置为false.
  3. 将StoreGeneratedPattern设置为计算.
  4. 将ConturrencyMode设置为固定.
  5. 创建SSDLTOSQL10.TT的副本(通常在C:\ Program Files(X86)\ Microsoft Visual Studio 10.0 \ Common7 \ common7 \ IDE \ Extensions \ Microsoft \ Microsoft \ Entity Framework Tools \ dbgen).让我们称其为myssdltosql10.tt.
  6. 编辑该行(当前151)说:

[<#= id(prop.name)#>] <#= prop.tostoretype()#>> <#= writeIdentity(prop,propsversion)#> <#= writEnullable(prop.nullable)#> <#<#<#<#<# =(p

  1. 将其更改为:
在#= prop.tostoryte()#>> <#}#> <#= witteridentity(prop,targeVersion)#>> <#= writEnullable(prop.nullable)#>> <#=(p

本文地址:https://www.itbaoku.cn/post/597479.html

问题描述

I got a problem with EF 4.0 I creating entity with "timestamp" column. After that, I try to generate database.

In SQL script column looks like 'binary(8)' instead of timestamp.

How to solve it ?

推荐答案

the problem solved: EF 4 could'n generate timestamp columns from edmx designer. The solution is easy:

  1. Set the type to binary.
  2. Set nullable to false.
  3. Set StoreGeneratedPattern to Computed.
  4. Set ConcurrencyMode to Fixed.
  5. Create a copy of SSDLToSQL10.tt (typically found in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\DBGen). Let's call it MySSDLToSQL10.tt.
  6. Edit the line (currently 151) that says:

[<#=Id(prop.Name)#>] <#=prop.ToStoreType()#> <#=WriteIdentity(prop, targetVersion)#> <#=WriteNullable(prop.Nullable)#><#=(p < entitySet.ElementType.Properties.Count - 1) ? "," : ""#>

  1. Change it to:

[<#=Id(prop.Name)#>] <#if (string.Compare(prop.Name,"TimeStamp",true) == 0) { #>timestamp<# } else { #><#=prop.ToStoreType()#><# } #> <#=WriteIdentity(prop, targetVersion)#> <#=WriteNullable(prop.Nullable)#><#=(p < entitySet.ElementType.Properties.Count - 1) ? "," : ""#>