Entity Framework timestamp Generate Database issue
Asked Answered
M

1

9

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 ?

Mccarty answered 6/7, 2010 at 7:6 Comment(0)
M
12

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

Mccarty answered 6/7, 2010 at 8:27 Comment(1)
@kayluhb In EF 5 it is not completely fixed but a lot easier. Just change the concurrency mode of the property to Fixed.Sorry

© 2022 - 2024 — McMap. All rights reserved.