问题描述
我有EF 4.0的问题 我使用"时间戳"列创建实体.之后,我尝试生成数据库.
在SQL脚本中,列看起来像"二进制(8)",而不是时间戳.
如何解决它?
推荐答案
解决的问题:EF 4可以从EDMX Designer生成时间戳列. 解决方案很容易:
- 将类型设置为二进制.
- 设置为false.
- 将StoreGeneratedPattern设置为计算.
- 将ConturrencyMode设置为固定.
- 创建SSDLTOSQL10.TT的副本(通常在C:\ Program Files(X86)\ Microsoft Visual Studio 10.0 \ Common7 \ common7 \ IDE \ Extensions \ Microsoft \ Microsoft \ Entity Framework Tools \ dbgen).让我们称其为myssdltosql10.tt.
- 编辑该行(当前151)说:
[<#= id(prop.name)#>] <#= prop.tostoretype()#>> <#= writeIdentity(prop,propsversion)#> <#= writEnullable(prop.nullable)#> <#<#<#<#<# =(p
- 将其更改为:
问题描述
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:
- Set the type to binary.
- Set nullable to false.
- Set StoreGeneratedPattern to Computed.
- Set ConcurrencyMode to Fixed.
- 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.
- Edit the line (currently 151) that says:
[<#=Id(prop.Name)#>] <#=prop.ToStoreType()#> <#=WriteIdentity(prop, targetVersion)#> <#=WriteNullable(prop.Nullable)#><#=(p < entitySet.ElementType.Properties.Count - 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) ? "," : ""#>