BlindingDawn
BlindingDawn

Reputation: 274

GUID not being generated automatically when db.submitchanges()

I have a couple of tables I ported over to a new database. Everything is exactly the same from the legacy one to the new one. The back-end code that submits the user generated data to the database is also the same. When I submit changes to the database, all of the submitted information populates the correct columns but the column that stores the GUID populates with all 0's. When I enter in the columns manually using SQL Server Management Studio, the GUID gets populated as it does in the legacy version. Am I missing something?

Upvotes: 1

Views: 280

Answers (2)

Kon
Kon

Reputation: 27431

I've had a similar issue with Entity Framework in the past, even though I have newid() set as default/initial value on the column. Due to time constraints, I didn't spend much time to resolve it and instead set the Guid property manually/explicitly to Guid.NewGuid() prior to saving.

Upvotes: 2

John Pick
John Pick

Reputation: 5650

When you ported over the tables, you must not have ported over the default value for one of the columns. E.g.

CREATE TABLE blah (
  blahID UNIQUEIDENTIFIER PRIMARY KEY DEFAULT NEWID()
)

Upvotes: 0

Related Questions