Note that there are some explanatory texts on larger screens.

plurals
  1. POCan I force Linq to Sql to use Sql2005Provider
    primarykey
    data
    text
    <p>This query (or rather one similar to it) is in a codebase we have already deployed.</p> <pre><code>var timeblocks = from tb in DB.TimeBlocks where tb.StartDate.Date.AddDays(1) &lt;= DateTime.Today select tb.Id; </code></pre> <p>DB is a datacontext that connects to the database. TimeBlocks is a fairly simple table, StartDate is a DateTime column.</p> <p>Currently the database is hosted on a Sql Server 2005 Installation, but we are in the process of upgrading to a Sql Server 2008 Installation.</p> <p>The query currently exectutes without problems.</p> <p>If we change the connection string to point at a copy of the same database running on Sql Server 2008 (with the compatability level set for 2005) the query fails with the SqlException:</p> <p>"The datepart millisecond is not supported by date function dateadd for data type date."</p> <p>This seems to be due to the different sql emitted by Linq to SQL when it connects to the 2008db (I assume this is because it uses Sql2008Provider instead of the Sql2005Provider). </p> <p>The 2005 Provider produces good SQL:</p> <pre><code>SELECT [t0].[Id] FROM [dbo].[TimeBlock] AS [t0] WHERE DATEADD(ms, (CONVERT(BigInt,@p0 * 86400000)) % 86400000, DATEADD(day, (CONVERT(BigInt,@p0 * 86400000)) / 86400000, DATEADD(HOUR, -DATEPART(HOUR, [t0].[StartDate]), DATEADD(MINUTE, -DATEPART(MINUTE, [t0].[StartDate]), DATEADD(SECOND, -DATEPART(SECOND, [t0].[StartDate]), DATEADD(MILLISECOND, -DATEPART(MILLISECOND, [t0].[StartDate]), [t0].[StartDate])))))) &lt;= @p1 </code></pre> <p>which successfully executes the query. However the sql emitted by the Sql2008Provider:</p> <pre><code>SELECT [t0].[Id] FROM [dbo].[TimeBlock] AS [t0] WHERE DATEADD(ms, (CONVERT(BigInt,@p0 * 86400000)) % 86400000, DATEADD(day, (CONVERT(BigInt,@p0 * 86400000)) / 86400000, CONVERT(DATE, [t0].[StartDate]))) &lt;= @p1 </code></pre> <p>Contains the erroneous sql that causes the exception.</p> <p>Am I right in thinking that the it is the Sql provider that is causing this problem? </p> <p>Is there a way we can get round this problem by forcing the DataContext to use the Sql2005Provider for this db?</p> <p>Thanks for any help you can give us!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload