I dont see PK, why?

Posts   
 
    
LLBLGen
User
Posts: 43
Joined: 10-Apr-2006
# Posted on: 19-Apr-2006 23:23:16   

When i save new entity using adapter, i don't see my PK. PK GUID is created in SQL.

// --------------- BookEntity newBook =new BookEntity ()

newbook.Name= "Some Book"; newBook.AuthorId=4;

ataAccessAdapter adapter = new DataAccessAdapter(); adapter.SaveEntity(newBook,true); MessageBox.Show(newBook.BookGUID.ToString());

//----------------

shows "0000-00-000...."

it did save the book,but why dit don't i see the BookGUID when i have refetchAfterSave=true?

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 20-Apr-2006 02:54:16   

A guid cannot be retrieved from the DB like an identity column can be. For this type of scenario you need to set the Guid before you execute your save.

// ---------------
BookEntity newBook =new BookEntity ()

newbook.Name= "Some Book";
newBook.AuthorId=4;
newBook.BookGUID = Guid.NewGuid();

ataAccessAdapter adapter = new DataAccessAdapter();
adapter.SaveEntity(newBook,true); 

LLBLGen
User
Posts: 43
Joined: 10-Apr-2006
# Posted on: 22-Apr-2006 02:21:07   

Thanks for your response.

Posts: 18
Joined: 26-Jul-2006
# Posted on: 27-Sep-2006 20:54:20   

This is my first real disappointment with LLBLGen. We use Guids exclusively for entity PKs (excluding some system tables that need to have corresponding enums). I hit this problem today and found this post, as well as another.

So, now I need to use Guid.NewGuid when saving an entity that is new... not that big of a deal I suppose, except that with SQL 2005, we have sequential guids available, which provide better indexing. So with LLBLGen, we can't take advantage of this feature.

Oh well. Still lovin' my first LLBLGen project :-)

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39797
Joined: 17-Aug-2003
# Posted on: 27-Sep-2006 21:39:54   

Of course you can take advantage of that feature, in LLBLGen Pro v2.0 support for NEWSEQUENTIALID() is build in. Simply define the default as NEWSEQUENTIALID() and you're good to go. Only works for PK's. Don't set the PK to a value.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 18
Joined: 26-Jul-2006
# Posted on: 28-Sep-2006 15:33:08   

Wow, I'm an ass. A search for NEWSEQUENTIALID() in the documentation clearly describes how to take advantage.

Well, alrighty then. Back to zero disappointments with LLBLGen smile

Thanks Frans!

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39797
Joined: 17-Aug-2003
# Posted on: 28-Sep-2006 16:41:54   

Pfew wink

Frans Bouma | Lead developer LLBLGen Pro