Dapper cast problem for timestamp fields

Can Aktepe 0 Reputation points
2024-03-07T10:12:56.0233333+00:00

Hi everyone, have you ever use Dapper in .Net. I use for the first time Dapper orm and I have problem with the cast join queries to a model. For example I have two tables and their names are relatively "groups" and "users". these tables joins with users.id field and groups.creator_id field. Also there are some timestamp fields in these tables. I get just the email_address field from the "users" table. Hovewer, when I join these 2 tables, the timestamp fields does not cast to model correctly.It seems to me date field is casted as min date value. What could be the reason for it? Or cause?

 User's image

 

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,148 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. AgaveJoe 26,191 Reputation points
    2024-03-07T12:45:58.22+00:00

    It seems to me date field is casted as min date value. What could be the reason for it? Or cause?

    The date field is probably empty or zero. The DateTime type defaults to zero which is the same as the minimum date time.

    Take a look in the groups table in the database and make sure the created_at date is not empty.


  2. Bruce (SqlWork.com) 55,196 Reputation points
    2024-03-07T17:18:09.4166667+00:00

    in c#, DateTime is a value type and can not be null. min date is the default. if you need null support then define the property as DateTime? (nullable type).