How to make LINQ use column default values?
Posted on 2009-07-11
I have a table with four columns. One column is a datetime, which uses the SQL Server function getdate() for the column's default value. When I drop this table onto my DBML in .NET, all four columns appear.
I never explicitly supply a value for the datetime column on inserts in .NET (C#) since I want to use the default provided from above in SQL Server. I have to delete the datetime column from the DBML since it breaks inserts. I get the SQL error that my date is out of range, since .NET, I assume, is trying to supply a datetime value for that column, rather than letting SQL Server do it.
The datetime column is needed for LINQ selects but not inserts. So, I do need the datetime column in the DBML for selects. How can I get around this issue so that the SQL Server default value is used on inserts, yet I can access the column for selects? Others entities, such as an SQL Server job may insert into this table. So the default of getdate() is necessary.