Insert null into uniqueidentifier column using LINQ and Sql Server 2008

Posted on 2009-04-23
Last Modified: 2013-11-11
I'm trying to insert nulls into a uniqueidentifier column in Sql Server 2008 using LINQ. I've tried the follwing all with the same result ... the value '00000000-0000-0000-0000-000000000000' instead of null is inserted.

Any help would be appreciated,

// First try ... 

tbl.fkAtrribute = Guid.Empty;

// Second try ...

Guid? fkAtrribute = null;

tbl.fkAtrribute = (Guid)fkAttribute;

Open in new window

Question by:grantmichaelfox
    LVL 8

    Expert Comment

    Just a guess cause im not LINQ expert but have you tried assigning:

    tbl.fkAttribute = DBNull.Value ;

    Author Comment

    This returns the error "Cannot convert type 'System.DBNull' to 'System.Guid?"
    LVL 11

    Expert Comment

    You need to go into your DBML file and set the "Nullable" property on that column to true.  At that point it should be a Guid? instead of just a plain Guid and you'll be able to set it to null.

    Author Comment

    The "Nullable" property is already set to true.

    Author Comment

    Argh ... i was casting Guid? to Guid.

    Problem solved.
    LVL 11

    Accepted Solution

    I thought you were doing that because your property was a Guid instead of a Guid? hense my answer ;).  Glad you figured it out.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
    Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
    HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now