2009-08-12 8 views
0

ce code fonctionne très bien sur SQL Express 2008:SubSonic 3.0.0.3 | SimpleRepository - OrderByDescending et .Premier()

return _repository.GetInstructions() 
     .Where(x => x.PublishedDate != null) 
     .OrderByDescending(x => x.PublishedDate) 
     .First(); 

mais lorsqu'il est exécuté en utilisant SQL Server 2000, il se casse. Voici l'erreur. Je posterai la trace si quelqu'un veut le voir.

FailedSystem.Data.SqlClient.SqlException: Line 1: Incorrect syntax near '('. 

est ici la trace:

TestSqlITInstructionRepository.Should_Get_Latest_ITInstruction : FailedSystem.Data.SqlClient.SqlException: Line 1: Incorrect syntax near '('. 
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) 
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) 
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) 
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) 
at System.Data.SqlClient.SqlDataReader.ConsumeMetaData() 
at System.Data.SqlClient.SqlDataReader.get_MetaData() 
at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) 
at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) 
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) 
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) 
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) 
at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) 
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior) 
at SubSonic.DataProviders.DbDataProvider.ExecuteReader(QueryCommand qry) in DbDataProvider.cs: line 137 
at SubSonic.Linq.Structure.DbQueryProvider.Execute<T>(QueryCommand`1 query, Object[] paramValues) in C:\Documents and Settings\nobody\My Documents\subsonic-SubSonic-3.0-8a52a0913ac0b8542d5d041262046c497387223f\subsonic-SubSonic-3.0-8a52a0913ac0b8542d5d041262046c497387223f\SubSonic.Core\Linq\Structure\DbQueryProvider.cs: line 280 
at lambda_method(ExecutionScope) 
at SubSonic.Linq.Structure.DbQueryProvider.Execute(Expression expression) in C:\Documents and Settings\nobody\My Documents\subsonic-SubSonic-3.0-8a52a0913ac0b8542d5d041262046c497387223f\subsonic-SubSonic-3.0-8a52a0913ac0b8542d5d041262046c497387223f\SubSonic.Core\Linq\Structure\DbQueryProvider.cs: line 131 
at SubSonic.Linq.Structure.QueryProvider.System.Linq.IQueryProvider.Execute<S>(Expression expression) in C:\Documents and Settings\nobody\My Documents\subsonic-SubSonic-3.0-8a52a0913ac0b8542d5d041262046c497387223f\subsonic-SubSonic-3.0-8a52a0913ac0b8542d5d041262046c497387223f\SubSonic.Core\Linq\Structure\QueryProvider.cs: line 45 
at System.Linq.Queryable.First<TSource>(IQueryable`1 source) 
at Kiss.Test.Repositories.TestSqlITInstructionRepository.Should_Get_Latest_ITInstruction() in TestSqlITInstructionRepository.cs: line 73 
+0

Pouvez-vous publier le sql généré par cette requête ainsi que la trace de la pile? –

+0

C'est un problème - J'ai posté une résolution ici: http://stackoverflow.com/questions/1397933/subsonic3-method-firstordefault-throws-exception-with-sql-server-2000/3466302#3466302 – DaveHogan

Répondre

1

Je ne pense pas que SubSonic soutient pleinement MS SQL 2000. Mes propres résultats indiquent que .Premier() genarates TOP (1)
Pour MS SQL 2000 il devrait être TOP 1 sans parenthèse

+0

C'est vrai, j'ai juste couru dans ce bug et je fiexed par votre réponse. Maintenant j'utilise SimpleRepository.Single au lieu de All et après First – Tom

0

Les docs SubSonic (http://subsonicproject.com/docs/Supported_Databases) disent qu'il supporte "SQL Server (200-2008)", ce qui signifie que c'est probablement un bug. Je pense que vous devriez probablement le soumettre comme un problème sur le site github SubSonic.

Questions connexes