LinqToDB.Common.LinqToDBConvertException: Cannot convert value '1/25/1980 12:00:00 AM: System.DateTime' to type 'System.DateOnly'
See original GitHub issueNot sure if .net 6.0 is completely supported at this point, but I’ve and issue with DateOnly fields. Query fails on materialization
Exception message: Cannot convert value '1/25/1980 12:00:00 AM: System.DateTime' to type 'System.DateOnly'
Stack trace:
LinqToDB.Common.LinqToDBConvertException: Cannot convert value '1/25/1980 12:00:00 AM: System.DateTime' to type 'System.DateOnly'
---> System.InvalidCastException: Invalid cast from 'System.DateTime' to 'System.DateOnly'.
at System.Convert.DefaultToType(IConvertible value, Type targetType, IFormatProvider provider)
at System.DateTime.System.IConvertible.ToType(Type type, IFormatProvider provider)
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
at LinqToDB.Common.ConvertBuilder.ConvertDefault(Object value, Type conversionType)
--- End of inner exception stack trace ---
at LinqToDB.Common.ConvertBuilder.ConvertDefault(Object value, Type conversionType)
at lambda_method1066(Closure , IDataReader )
at LinqToDB.Expressions.ConvertFromDataReaderExpression.ColumnReader.GetValue(IDataReader dataReader)
at lambda_method1059(Closure , IQueryRunner , IDataReader )
at LinqToDB.Linq.QueryRunner.Mapper`1.Map(IDataContext context, IQueryRunner queryRunner, IDataReader dataReader)
at LinqToDB.Linq.QueryRunner.ExecuteQueryAsync[T](Query query, IDataContext dataContext, Mapper`1 mapper, Expression expression, Object[] ps, Object[] preambles, Int32 queryNumber, Func`2 func, TakeSkipDelegate skipAction, TakeSkipDelegate takeAction, CancellationToken cancellationToken)
at LinqToDB.Linq.QueryRunner.ExecuteQueryAsync[T](Query query, IDataContext dataContext, Mapper`1 mapper, Expression expression, Object[] ps, Object[] preambles, Int32 queryNumber, Func`2 func, TakeSkipDelegate skipAction, TakeSkipDelegate takeAction, CancellationToken cancellationToken)
at LinqToDB.Linq.QueryRunner.ExecuteQueryAsync[T](Query query, IDataContext dataContext, Mapper`1 mapper, Expression expression, Object[] ps, Object[] preambles, Int32 queryNumber, Func`2 func, TakeSkipDelegate skipAction, TakeSkipDelegate takeAction, CancellationToken cancellationToken)
at LinqToDB.Linq.ExpressionQuery`1.GetForEachAsync(Action`1 action, CancellationToken cancellationToken)
at LinqToDB.AsyncExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken token)
at Vtbf.Contractors.Application.CQRS.ContractorsLegal.ContractorLegalQueryByFilter.Handler.SelectWithSearchQueryAsync(ContractorLegalQueryByFilter request, CancellationToken cancellationToken) in /home/konstantin/sources/....cs:line 82
Steps to reproduce
Fails on materialization
Environment details
linq2db version: 3.6 Database Server: Postgres 14 Database Provider: Npgsql.EntityFrameworkCore.PostgreSQL 6.0.1 Operating system: Ubuntu 21.10 .NET Framework: .net 6.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
How to convert System.DateTime? to System.DateOnly?
So DateTime? to DateOnly? The error says: Error CS0029 Cannot implicitly convert type 'System.DateOnly?' to 'System.DateTime?' I can convert ...
Read more >DateOnly.FromDateTime(DateTime) Method (System)
Returns a DateOnly instance that is set to the date part of the specified dateTime.
Read more >Date, Time, and Time Zone Enhancements in .NET 6
In this blog post, I'm going to cover the following topics: The new DateOnly and TimeOnly types; Time Zone Conversion APIs; Time Zone...
Read more >Converting DateOnly and TimeOnly to DateTime and vice ...
Since I have introduced DateOnly and TimeOnly feature of .NET 6 in my previous article( Simplified Date and Time with DateOnly and TimeOnly...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@SteveDunn I haven’t implemented
TimeOnly
yet - haven’t found a use for it yet. If you need it, I’ll put something together soon.You just need to define
DateTime => DateOnly
conversion in your mapping schema.but yes, we need to embedd those conversions into linq2db at some point.