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

查看:166
本文介绍了实体框架时间戳生成数据库问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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:


  1. 将类型设置为二进制。


  2. 将StoreGeneratedPattern设置为Computed。

  3. 将ConcurrencyMode设置为Fixed。

  4. SSDLToSQL10.tt(通常位于C:\Program Files(x86)\ Microsoft Visual Studio 10.0 \Common7 \IDE\Extensions\Microsoft\Entity Framework Tools\DBGen)。让我们称之为MySSDLToSQL10.tt。

  5. 编辑该行(目前为151):

  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)? ,:#>

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


  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆