SubSonic Forums
All Your Database Are Belong To Us

The curse of Guid?

Latest post 10-25-2008 3:44 PM by kianryan. 3 replies.
  • 10-25-2008 7:11 AM

    The curse of Guid?

    A project I'm currently working on has just switched from int IDENTITY to Guids for their primary keys, populated by newsequentialid().  I've regenerated the DAL, and am now in a position where new items committed to the db are generating guids correctly in the table, but aren't populating the PK in the item. I'm using the repository pattern.

    For example:

    CREATE TABLE tblItem
    (
    ItemId uniqueidentifier DEFAULT (newsequentialid()) NOT NULL PRIMARY KEY,
    Description NVARCHAR(255) NOT NULL
    )
    
    Item item = new Item();
    item.Description = "Bow chicka wow-wow.";
    DB.Save(item);
    Console.Writeline(item.ItemId);
    // Outputs Guid.Empty where db reports 2F1FC274-76A2-DD11-8F92-000C29CA8213
    

    After a bit of googling, I was unable to determine if this has been resolved or not. Relevant work items appear "closed" but with no explination as to resolution, and all I appear to get from the forums at this point is confusion.  Currently using 2.1 Final.

    Filed under: ,
  • 10-25-2008 12:50 PM In reply to

    Re: The curse of Guid?

    I've found the offending chunk of generated code.

    	colvarItemId.DefaultSetting = @"DEFAULT";
    

    If I comment this line out, then the item commits successfully to the db, and everything is hunky dory. I've tried flipping the setPropertyDefaultsFromDatabase on and off, and there's no change there. It's a bit of a of a clutz having to do this every time I regenerate the DAL, put at least I've got a solution.

  • 10-25-2008 3:20 PM In reply to

    Re: The curse of Guid?

     The problem here is this:

    DEFAULT (newsequentialid())

    SubSonic is reading that there is a default value for the column, and is telling the DB to use the DEFAULT, which normally works for other column data types but does not for a GUID. I've tried to figure a way around Sequential guids and it's just not possible for SubSonic, unfortunately.

     

     

    Find a bug? Create a Work Item for a fast response.. Want to help? Create a patch for us!

  • 10-25-2008 3:44 PM In reply to

    Re: The curse of Guid?

    Well, commenting out the defaultvalue (as above) seems to be working okay.

Page 1 of 1 (4 items) | RSS