This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hey Guys, Lightspeed file version: 4.0.1103.19500 query: var count = (from r in reservations where (r.DepartureDate - r.ArrivalDate).TotalDays <= i && (r.DepartureDate - r.ArrivalDate).TotalDays >= i - 1 select r).Count(); exception: [NullReferenceException: Object reference not set to an instance of an object.]
..( ) +14
..( ) +21
..( ) +34
..( ) +103
Mindscape.LightSpeed.Sql.SelectStatement.( ) +41
..( ) +21
..() +117
..(String , IdentifierExpression , Query ) +614
Mindscape.LightSpeed.UnitOfWork.Calculate(String calculation, IdentifierExpression attribute, Query query) +91
Mindscape.LightSpeed.UnitOfWork.Count(Query query) +90
Mindscape.LightSpeed.Linq.Plan.<>cDisplayClass9. questions:
As always, thanks a lot for your wise words! Finest regards, Dennis |
|
|
Extra information: query: var count = (from r in Repository.FindAll exception: [OverflowException: SqlDbType.Time overflow. Value '1.00:00:00' is out of range. Must be between 00:00:00.0000000 and 23:59:59.9999999.]
System.Data.SqlClient.TdsParser.WriteTime(TimeSpan value, Byte scale, Int32 length, TdsParserStateObject stateObj) +940389
System.Data.SqlClient.TdsParser.WriteValue(Object value, MetaType type, Byte scale, Int32 actualLength, Int32 encodingByteSize, Int32 offset, TdsParserStateObject stateObj) +5172926
System.Data.SqlClient.TdsParser.TdsExecuteRPC(_SqlRPC[] rpcArray, Int32 timeout, Boolean inSchema, SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj, Boolean isCommandProc) +5048
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout) +1012
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource comments: It seems we are getting somewhere now. I will try more variations. |
|
|
Now using 23 hours as limit for the less or equal comparison. query: var count = (from r in Repository.FindAll exception: [SqlException (0x80131904): The data types datetime and time are incompatible in the less than or equal to operator.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +1875018
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +5196252
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +356
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +897
System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() +69
System.Data.SqlClient.SqlDataReader.get_MetaData() +90
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +376
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout) +1012
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource query dispatched: SELECT COUNT(*) FROM [Reservations] WHERE ([Reservations].[DepartureDate] - [Reservations].[ArrivalDate]) <= '23:00:00' Clearly can't get it to work with LINQ, but here is some information that is hopefully helpful... |
|
|
Thanks for the info. It looks like that SQL Server datetime/time issue makes the LINQ approach a nonstarter for now, but we will look into improving this. In the meantime, I think you will need to fall back to query objects, which allow you to bypass LINQ typechecking and give SQL Server the data types it needs. The following approach seemed to work for me:
Another approach which doesn't rely on ugly DateTimes but winds up rather messier and more SQL Server-specific is to convert the time difference expression to a time instead of leaving it a datetime, by invoking the SQL Server CONVERT function:
(See the LightSpeed docs for information about the weird positional |
|