Filtering on a DateTimeOffset column throws exception

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
skylight0514
Posts: 1
Joined: Fri 10 Jun 2022 13:08

Filtering on a DateTimeOffset column throws exception

Post by skylight0514 » Fri 10 Jun 2022 13:52

Hello folks,

using the latest version when filtering on a DateTimeOffset column (MSSQL) doesn't work and throws the following exception:

Code: Select all

System.NotSupportedException: The method is not supported with specified arguments.
   bei Devart.Data.Linq.Engine.DbMethodCallConverter.a(List`1 A_0, List`1 A_1, List`1 A_2, Type A_3, Object A_4)
   bei Devart.Data.Linq.Engine.DbMethodCallConverter.c(SqlBinary A_0)
   bei Devart.Data.Linq.Engine.DbMethodCallConverter.b(c4 A_0)
   bei Devart.Data.Linq.Engine.SqlVisitor.Visit(SqlNode node)
   bei Devart.Data.Linq.Engine.SqlVisitor.g(SqlExpression A_0)
   bei Devart.Data.Linq.Engine.SqlVisitor.h(SqlSelect A_0)
   bei Devart.Data.Linq.Engine.DbMethodCallConverter.e(SqlSelect A_0)
   bei Devart.Data.Linq.Engine.SqlVisitor.c(h A_0)
   bei Devart.Data.Linq.Engine.DbMethodCallConverter.a(h A_0)
   bei Devart.Data.Linq.Engine.SqlVisitor.Visit(SqlNode node)
   bei Devart.Data.Linq.Engine.cy.a(SqlNode A_0, ResultShape& A_1)
   bei Devart.Data.Linq.Engine.cy.d(Expression A_0)
   bei Devart.Data.Linq.Engine.cy.f(Expression A_0)
   bei Devart.Data.Linq.DataProvider.a(Expression A_0)
   bei Devart.Data.Linq.Engine.DataQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
   bei System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   bei System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   bei Program.Main()
You can reproduce it with the following code:

Code: Select all

using Devart.Data.Linq;
using Devart.Data.Linq.Mapping;
using Devart.Data.SqlServer.Linq.Provider;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Linq;

internal class Program
{
	[Provider(typeof(SqlDataProvider))]
	class SqlDataContext : DataContext
	{
		public SqlDataContext(IDbConnection connection) : base(connection)
		{
		}
	}

	class QueryTypeDateTimeOffset
	{
		public DateTimeOffset DateTimeOffset { get; set; }
	}

	static void Main()
	{
		SqlConnectionStringBuilder connectionStringBuilder = new SqlConnectionStringBuilder()
		{
			DataSource = @"(LocalDB)\MSSQLLocalDB",
			IntegratedSecurity = true,
		};

		SqlConnection connection = new SqlConnection(connectionStringBuilder.ToString());

		SqlDataContext dataContext = new SqlDataContext(connection);

		string query = @"SELECT DATEADD(DAY, -1, SYSDATETIMEOFFSET()) AS DateTimeOffset
	UNION
	SELECT DATEADD(DAY, 1, SYSDATETIMEOFFSET())";

		var queryable = dataContext.Query<QueryTypeDateTimeOffset>(query);

		var result = queryable
			.Where(row => row.DateTimeOffset >= DateTimeOffset.Now)
			.ToList();
	}
}
This there any chance that you can fix this in a future version?

Greetings,
Kai

Post Reply