entity framework - Concurrency timestamp column stays null with computed -


i'm using ef - model first saving entities. i've added column "rowversion" options:

enter image description here

in metadata class added annotation [timestamp].

but when add/insert entity in table property rowversion stays null. insert won't because set column nullable otherwise keeps running exception telling me rowversion null.

how solve this?

i seeing exact same behavior. have worked on afternoon , thing able work implement solution @ link: http://www.undisciplinedbytes.com/2012/03/creating-a-timestamp-column-with-entity-framework/

here steps copied link:

timestamp column model-first approach

now, setting column model-first approach little bit trickier. there’s no built-in support in ef’s model (yet), we’ll have hack code generation template fulfill our needs.

what need set timestamp column using model first approach following:

  1. add property named “timestamp” entity in ef’s model
  2. set type binary
  3. set nullable false
  4. set storegeneratedpattern computed
  5. set concurrencymode fixed
  6. create copy of ssdltosql10.tt (typically found in c:\program files (x86)\microsoft visual studio 10.0\common7\ide\extensions\microsoft\entity framework tools\dbgen)
  7. edit line says:

[<#=id(prop.name)#>] <#=prop.tostoretype()#> <#=writeidentity(prop, targetversion)#> <#=writenullable(prop.nullable)#><#=(p < entityset.elementtype.properties.count - 1) ? "," : ""#>

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

this change column called “timestamp” (case insensitive) timestamp column.

  1. click on entity canvas , set ddl generation template new copy of file
  2. click on generate database model 10.enjoy new concurrency-aware data access!

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -