Employee.DateOfBirth is not a supported primitive type or a valid entity type

Tauqeer 1 Reputation point
2021-12-17T13:12:07.367+00:00

Hi,

In my model, I have

public class Employees
{
public int ID { get; set; }
public string firstName { get; set; }
public string lastName { get; set; }
public DateTime dateOfBirth { get; set; }
}
when I did

dotnet ef migrations add Initial
I got

The property 'Employee.DateOfBirth' could not be mapped, because it is of type 'Date' which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it.
Is this what it supposed to be?

I have the smiler quest about list in this form. Do you think I the date format also be hander in the similar way. ? I am using angular calendar to pick the date and also I have edit function int.

Thanks!

Developer technologies | .NET | Entity Framework Core
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Adam Jachocki 46 Reputation points
    2021-12-17T14:55:20.963+00:00

    The most important here is - what DBMS you have? MSSQL? SQLite? MariaDB?
    Your DBMS doesn't know what "DateTime" is. You should map this data type, for example:

    [Column(TypeName("data-type-in-your-dbms"))]
    public DateTime dateOfBirth {get;set;}
    
    • you can store your datetime as ints (for example in unix timestamp) like this: public int dateOfBirthTimestamp {get;set;} //this one is written to db
      public DateTime dateOfBirth
      {
      get { return DateTime.FromTimestamp(dateOfBirthTimestamp); }
      set {dateOfBirthTimestamp = value.ToTimeStamp(); }
      }

    (this is pseudocode, so you should read about timestamp)

    or the best - try using DateTimeOffset - but this one may not be provided in for example SQLite.

    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.