entity framework - Concurrency timestamp column stays null with computed -
i'm using ef - model first saving entities. i've added column "rowversion" options:
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:
- add property named “timestamp” entity in ef’s model
- set type binary
- set nullable false
- set storegeneratedpattern computed
- set concurrencymode fixed
- 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)
- 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.
- click on entity canvas , set ddl generation template new copy of file
- click on generate database model 10.enjoy new concurrency-aware data access!
Comments
Post a Comment