How to use Date Only as data type in Entity Framework
11,290
Use the following
[Column(TypeName="Date")]
public DateTime ReportDate { get; set; }
Author by
Yoa
Updated on June 26, 2022Comments
-
Yoa almost 2 years
When I use Entity Framework as an ORM, for each
Date
data type in my SQL Server DB it creates aDateTime
data typey
in my MVC project.I mean, for each table in my DB, in my MVC project is auto-generated the code for this class using
DateTime
data type, but I don't need time, only the date.So my question is: what can I do to declare this field as
Date
only data type or How is commonly handled this situation?.public partial class Employee { public int Id_Employee { get; set; } public string Name { get; set; } public string Last_Name { get; set; } public Nullable<System.DateTime> B_Date { get; set; } public Nullable<int> SSN_L4 { get; set; } public string Phone_N { get; set; } public string Adress_L1 { get; set; } public string Adress_City { get; set; } }