Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Date Only as data type in Entity Framework [duplicate]

When I use Entity Framework as an ORM, for each Date data type in my SQL Server DB it creates a DateTime data type y 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; }        
}
like image 807
Yoa Avatar asked Aug 10 '15 05:08

Yoa


1 Answers

Use the following

[Column(TypeName="Date")]
public DateTime ReportDate { get; set; }
like image 57
Sam Avatar answered Oct 27 '22 17:10

Sam