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,815 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. AgaveJoe 30,031 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) 74,146 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).


  3. Bruno Legrand 0 Reputation points
    2024-09-09T15:52:37.1466667+00:00

    I have exactly the same problem.

    The date is not null while querying directly in SQL Server management studio


  4. Bruno Legrand 0 Reputation points
    2024-09-10T14:44:49.5933333+00:00

    Here is the schema used.

    I tried several fields for spliton, bnut I never get the date

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.