[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2072
  • Last Modified:

Insert null into uniqueidentifier column using LINQ and Sql Server 2008

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,

Grant.
// First try ... 
tbl.fkAtrribute = Guid.Empty;
 
 
// Second try ...
Guid? fkAtrribute = null;
tbl.fkAtrribute = (Guid)fkAttribute;

Open in new window

0
grantmichaelfox
Asked:
grantmichaelfox
  • 3
  • 2
1 Solution
 
WikkardCommented:
Just a guess cause im not LINQ expert but have you tried assigning:

tbl.fkAttribute = DBNull.Value ;
0
 
grantmichaelfoxAuthor Commented:
This returns the error "Cannot convert type 'System.DBNull' to 'System.Guid?"
0
 
b_levittCommented:
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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
grantmichaelfoxAuthor Commented:
The "Nullable" property is already set to true.
0
 
grantmichaelfoxAuthor Commented:
Argh ... i was casting Guid? to Guid.

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

B
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now