I'm quite new to this, I'm using MVC view model that has a property with Datetime
type :
namespace FP.WebUI.Models
{
public class AdminSessionsViewModel
{
NewSession _NewSession = new NewSession();
public NewSession NewSession { get { return _NewSession; } set { _NewSession = value; } }
public IEnumerable<Sessions> CurrentSessions { get; set; }
}
public class NewSession
{
[Required]
public string Title { get; set; }
public string Description { get; set; }
[Required]
public DateTime Date { get; set; }
}
}
I want Date
property to be like this format : 27/05/2013 06:44AM and the same inside SQL database.
I really don't know how to configure Date
inside the NewSession
class to automatically get shown like this inside my Textbox and when mapped back to Entity Framework will be saved inside the database like this.
Here's my entity framework fluent API configuration :
namespace FP.Domain.Configurations
{
public class SessionsConfig : EntityTypeConfiguration<Sessions>
{
public SessionsConfig()
{
ToTable("Sessions");
Property(p => p.Name).IsRequired();
Property(p => p.PhotosCount).IsRequired();
Property(p => p.CoverPhoto).IsRequired();
Property(p => p.Date).HasColumnType("datetime2").HasPrecision(0);
}
}
}