Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1014179
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:12:54+00:00 2026-05-16T10:12:54+00:00

For my primary key and identity in our Clients table I use uniqueidentifier column

  • 0

For my primary key and identity in our Clients table I use uniqueidentifier column with a default value set to newsequentialid(). Inserting new rows through the management tool creates the values for the ID fine.

Inserting from .NET 4 code via EF results into zero GUIDs (00000-0000….) being inserted. I create the entity with new, set some values and perform EF AddToClients (for instance). If debugged, value for the id property shows zero GUID. I do not explicitly set the id via the Guid.NewGuid() in my code because I want to leave it off to the newsequentialid() in SQL Server. The problem is, it doesn’t work. The first time the code is executed row gets inserted with zero GUID. The next time it obviously fails and results in primary key violation exception.

How can I get this to work without having to set the GUID in my client code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:12:55+00:00Added an answer on May 16, 2026 at 10:12 am

    You need to change the StoreGeneratedPattern value for the property in the EF designer. Set it to Identity. This will cause EF to avoid setting the value on an insert, then capture it after the insert is complete.

    Note that if you’re using EF 4, you may have trouble with this using the designer only (see this link). You may have to edit the .edmx manually and set the StoreGeneratedPattern in the storage model itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a table with an identity column as the primary key, so
My database has a parent table with an auto-incrementing primary key identity 'ID', and
create table ImagenesUsuario { idImagen int primary key not null IDENTITY } This doesn't
CREATE TABLE SupplierQuote ( supplierQuoteID int identity (3504,2) CONSTRAINT supquoteid_pk PRIMARY KEY, PONumber int
I have something like this: create table account ( id int identity(1,1) primary key,
Given these tables: create table Orders ( Id INT IDENTITY NOT NULL, primary key
We use GUIDs for primary key, which you know is clustered by default. When
create table [User] ( UserId int primary key identity(1,1), FirstName nvarchar(256) not null, LastName
I'm trying to query a datatable to establish the primary key [identity column], by
Say I have a table with the following layout: Id Int PRIMARY KEY IDENTITY

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.