With LINQ to SQL, you can map many SQL Server date and time types. The following table shows the CLR types that O/R Designer and SQLMetal select when building an object model or external mapping file based on your database.
The next table shows the default type mappings used by the DataContext..::.CreateDatabase method to define which type of SQL columns are created to map to the CLR types defined in your object model or external mapping file.
There are many other date and time mappings you can choose, but some may result in overflow or data loss exceptions while translating to or from the database. For more information, see the Type Mapping Run Time Behavior Matrix.
Note: |
|---|
The SQL Server types
DATETIME2, DATETIMEOFFSET, DATE, and TIME are available starting with Microsoft SQL Server 2008. LINQ to SQL supports mapping to these new types starting with the .NET Framework version 3.5 SP1.
|
System.Datetime
System.TimeSpan
Microsoft SQL Server 2008 and the .NET Framework 3.5 SP1 let you map the CLR System..::.TimeSpan type to the SQL Server TIME type. However, there is a large difference between the range that the CLR System..::.TimeSpan supports and what the SQL Server TIME type supports. Mapping values less than 0 or greater than 23:59:59.9999999 hours to the SQL TIME will result in overflow exceptions. For more information, see System.TimeSpan Methods (LINQ to SQL).
In Microsoft SQL Server 2000 and SQL Server 2005, you cannot map database fields to TimeSpan. However, operations on TimeSpan are supported because TimeSpan values can be returned from DateTime subtraction or introduced into an expression as a literal or bound variable.