最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Handling TimeSpan type conversion issue in .NET 8 with Fluent NHibernate after migrating from .NET Framework - Stack Overfl

programmeradmin2浏览0评论

Can someone help me? I'm encountering an issue with the TimeSpan datatype in .NET 8 using FluentNHibernate.Mapping.

To summarize, my project was initially on .NET Framework 4, and I recently migrated it to .NET Core 8. However, all the fields in my entities that were of type TIME now return the following error in the SQL result:

System.FormatException: Input string '07:30:00' was not in the correct format.

System.InvalidCastException: Unable to cast object of type 'System.DateTime' to type 'System.TimeSpan'.

Even after changing the type of the variable in the entity class to TimeSpan, the error persists but with a slightly different message:

System.FormatException: Input string '07:30:00' was not in the correct format.

System.InvalidCastException: Unable to cast object of type 'System.TimeSpan' to type 'System.IConvertible'.

I have already tried using .CustomType<TimeAsTimeSpanType>() and implemented a custom converter for JSON deserialization, but when I run a dynamic SQL query with a generic return (e.g., IList<dynamic>), this error occurs.

Does anyone know another way to handle the TIME datatype while still using FluentNHibernate?

Additional information for context:

  • PostgreSQL database:
  • Column type: TIME

Code in my C# entity:

public virtual TimeSpan column_time { get; set; }

Class mapping:

Map(x => x.column_time).Column("column_time")
                       .CustomType<TimeAsTimeSpanType>();

Let me know if anything else is needed or if there are further issues!

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论