V
Vaccano
I have an issue with Linq to SQL using a Null FK. Here is the situation.
Two Tables:
TableA
PKColumn UniqueIdentifier
<Other Columns>
TableB
PKColumn int
FKColumn UnqiueIdentifer (can be Null) --This is a FK to table A PKColumn.
I create all of this in my Linq To SQL designer (using normal drag and drop
methods) and then when I try to call:
dataContext.TableB.InsertAllOnSubmit<TableB>(ListOfTableBs);
dataContext.SubmitChanges();
on objects that have the FKColumn set to null I get the following exception:
Specified cast is not valid.
I have checked and double checked that my values that allow nulls are all
correct (the FKColumn is set to allow nulls in both the DB and the designer.)
Note that the insert works fine when the FKColumn value is a valid guid.
I have also run straight SQL and Sprocs to do the insert of the data and
that works too (just to ensure that my data schema was correct.)
I have tried to override the Insert portion of my TableB object in the Linq to
SQL Designer to use a working sproc but I still get the same exception.
The lack of any real info (from the debugger) on what has gone wrong makes
this error even more frustrating. (The call stack says nothing useful.)
Any ideas or fixes would be greatly appreciated.
Vaccano
Two Tables:
TableA
PKColumn UniqueIdentifier
<Other Columns>
TableB
PKColumn int
FKColumn UnqiueIdentifer (can be Null) --This is a FK to table A PKColumn.
I create all of this in my Linq To SQL designer (using normal drag and drop
methods) and then when I try to call:
dataContext.TableB.InsertAllOnSubmit<TableB>(ListOfTableBs);
dataContext.SubmitChanges();
on objects that have the FKColumn set to null I get the following exception:
Specified cast is not valid.
I have checked and double checked that my values that allow nulls are all
correct (the FKColumn is set to allow nulls in both the DB and the designer.)
Note that the insert works fine when the FKColumn value is a valid guid.
I have also run straight SQL and Sprocs to do the insert of the data and
that works too (just to ensure that my data schema was correct.)
I have tried to override the Insert portion of my TableB object in the Linq to
SQL Designer to use a working sproc but I still get the same exception.
The lack of any real info (from the debugger) on what has gone wrong makes
this error even more frustrating. (The call stack says nothing useful.)
Any ideas or fixes would be greatly appreciated.
Vaccano