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 7644107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:36:20+00:00 2026-05-31T09:36:20+00:00

I am creating and filling LINQ to SQL objects programatically and then adding them

  • 0

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. 
  1. I know that I can assign the PK using myNewRecord.pk=Guid.newGuid()
    Guid is all 0's (zeros)?
  2. 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?

  • 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-31T09:36:21+00:00Added an answer on May 31, 2026 at 9:36 am

    Guid’s are value types, thus they cannot be null. That means when a Guid is created, it has to assign a default value (which is all 0’s). SQL Server does not automatically generate GUID’s for primary keys like it does for Identity columns. You can set the default value to NEWID(), but by default EF will ignore that and try to insert a value. You can override this by doing something like described here

    http://softmindit.blogspot.com/p/using-guid-as-entitykey-in-entity.html

    EDIT: I just realized you’re using Linq to sql not Linq to entities. However, i’m sure there’s something similar in L2S to deal with this.

    Edit2: There is a similar thing in linq to sql, as shown in the screenshot. Changing this property fixes the problem

    enter image description here

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

Sidebar

Related Questions

I'm creating some UILabels in my UIView , filling them with data, adding them
I'm dynamically creating some <div> elements and then filling their innerHTML properties with text.
Creating a server-side socket will fail if I'm trying to use the same port
I am creating an HTML report (it's to be a form for filling in).
Seems simple enough - I'm creating one master NSMutableDic and filling it with more
I have an object which I'm filling with objects containing 2 table rows each.
I am creating the Android version of an iPhone app, and i need them
I am creating an email intent and filling the message with a link that
I'm creating a custom cell in the cellForRowAtIndex function and filling it with my
I am creating a calendar using GridView (6 row * 8 column). Each of

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.