I am creating and filling LINQ to SQL objects programatically and then adding them to a sql server database with a uniqueidentifier column for a PK. LINQ is automatically assigning a PK of all 0s. This creates errors upon insert because the PK is a duplicate.
Dim myNewRecord as IceCreamTrackerTable
myNewRecord.name=Bob
myNewRecord.favoriteIceCream=Vanilla
'myNewRecord.PK=00000000-0000-0000-0000-000000000000 (by default)'
myDataContext.IceCreamTrackerTables.insertOnSubmit(myNewRecord)
''second record added throws an error because it also has PK 00000 etc.
- I know that I can assign the PK using myNewRecord.pk=Guid.newGuid() Guid is all 0's (zeros)?
- But what I really want is for SQL server to be assigning the GUIDs because I'm assuming that it has some method to make sure that it is not re-assigning the same guid
Is there any way to tell LINQ that I don't want to fill the GUID myself but leave it up to SQL server?