实体框架时间戳生成数据库问题 [英] Entity Framework timestamp Generate Database issue
问题描述
我有一个EF 4.0的问题
我创建实体与timestamp列。之后,我尝试生成数据库。
I got a problem with EF 4.0 I creating entity with "timestamp" column. After that, I try to generate database.
在SQL脚本列中看起来像'binary(8)'而不是时间戳。
In SQL script column looks like 'binary(8)' instead of timestamp.
如何解决?
推荐答案
问题解决:EF 4无法从edmx设计器生成时间戳列。
解决方案很简单:
the problem solved: EF 4 could'n generate timestamp columns from edmx designer. The solution is easy:
- 将类型设置为二进制。
- 将StoreGeneratedPattern设置为Computed。
- 将ConcurrencyMode设置为Fixed。
- SSDLToSQL10.tt(通常位于C:\Program Files(x86)\ Microsoft Visual Studio 10.0 \Common7 \IDE\Extensions\Microsoft\Entity Framework Tools\DBGen)。让我们称之为MySSDLToSQL10.tt。
- 编辑该行(目前为151):
- 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)? ,:#>
[<#=Id(prop.Name)#>] <#=prop.ToStoreType()#> <#=WriteIdentity(prop, targetVersion)#> <#=WriteNullable(prop.Nullable)#><#=(p < entitySet.ElementType.Properties.Count - 1) ? "," : ""#>
- 将其更改为:
[<#= 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)? ,:#>
[<#=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) ? "," : ""#>
这篇关于实体框架时间戳生成数据库问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!