GUID ID of newly inserted record

Posts   
 
    
Kchakra
User
Posts: 1
Joined: 15-Feb-2007
# Posted on: 16-Feb-2007 00:03:08   

Hi I am using July 24 2006 release Version 2.0.0.0 final on Sql 2005 , SelfService

I know that after Save() the entity normally gets updated with the ID of the newly created record. But this is not happening for me since my PK is added using a default constraint using the following code on the DB

ALTER MyTable xyz ADD CONSTRAINT [DF_xyz] DEFAULT (newid()) FOR [MyTableID]

Now If I use the following code,

EntityClasses.MyTable myTable= new EntityClasses.MyTable(); myTable.Name = "blah"; myTable.Age = "blah"; myTable.Save(); Guid g = myTable.MyTableID; g does not get the ID value. Instead it gets {000000000-000000-00000........}

Is there a way I can get the PK guid of a newly inserted record in the table wich gets updated using the default constraint? Regards, Krishna

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 16-Feb-2007 01:50:24   

Take a look at this thread. http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=6327&HighLight=1 I believe version 2 of llblgen will allow the refetch of an entity with a guid PK if you are using SQL2005, which it looks like you are.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 16-Feb-2007 09:46:17   

You have to use NEWSEQUENTIALID() in sqlserver 2005 as the default. If you use another default, you have to set the Id manually in code.

Oh, and as you're using an old runtime, I suggest to upgrade to the latest build, we fixed a couple of issues since July 24th wink (not related to this though)

Frans Bouma | Lead developer LLBLGen Pro