title: SQL Server 2005: Nullable Foreign Key Constraint
body: <p>I have a foreign key constraint between tables Sessions and Users. Specifically, Sessions.UID = Users.ID. Sometimes, I want Sessions.UID to be null. Can this be allowed? Any time I try to do this, I get an FK Constraint Violation.</p>
  
  <p>Specifically, I'm inserting a row into Sessions via LINQ. I set the Session.User = null; and I get this error: 
  <PRE>An attempt was made to remove a relationship between a User and a Session. However, one of the relationship's foreign keys (Session.UID) cannot be set to null.</PRE></p>
  
  <p>However, when I remove the line that nulls the User property, I get this error on my SubmitChanges line:
  <PRE>Value cannot be null.
  Parameter name: cons</PRE></p>
  
  <p>None of my tables have a field called 'cons', nor is it in my 5,500-line DataContext.designer.cs file, nor is it in the QuickWatch for any of the related objects, so I have no idea what 'cons' is.</p>
  
  <p>In the Database, Session.UID is a nullable int field and User.ID is a non-nullable int. I want to record sessions that may or may not have a UID, and I'd rather do it without disabling constraint on that FK relationship. Is there a way to do this?</p>