How do I set Auto-Generated-Values and Auto-Sync with SQL Metal or in Code

709 Views Asked by At

It's 1:30am for me now, so I'm sorry if there are any confusing bits in here.. it seems to make sense in my head.. :-)

I've been using SQLMetal to generate a data context for my database tables...

I used the command:

sqlmetal.exe /server:dbsvr\sqlexpress /database:"TestDB" /user:sa /password:password /namespace:DB_Data /context:DBDataContext /code:DBDataContext.cs /map:DB.map

This all works fine, I can do all the CRUD functions on my tables, etc... well almost..

I have a "header" table that has a field of type "uniqueidentifier"... when I insert a new record, I want the database to assign the value to the record and for my header table record to be updated with the new guid from the database. at the moment, any new record I add to the table has all zeros for the id guid field.. so when I try to add a second record, it fails with a duplicate key.

In my hunting for an answer I came across this post: SQL Server 2008 GUID column is all 0's

It mentions setting the "Auto Generated Values" and "Auto Sync" to "True" and "OnInsert" respectively in the dbml.

My problem is, that I don't have a dbml file, because it wasn't created when I ran the SQLMetal command. I used the .map file generation parameters instead.. I realise there is a "/dbml" flag, but I don't know which one to use..

Should I be using the dbml file instead of, or as well as the map file???

Or is there a way that in code, when I create a new header record variable, I can just say something like the following to tell the system to use the DB's generated ID value and update my record variable.... : recHdr.Id.AutoGeneratedVales = True; recHdr.Id.AutoSync = OnInsert;

Many thanks...

0

There are 0 best solutions below