If so, (which I now doubt), please supply details. My test is detailed here, I really need some help.
The server date format is dd/MM/yyyy.
Definition for table Test:
CalendarDate datetime2(7) Key
Name nvarchar(50)
BirthDate datetime2(7)
Data 2018-04-15 00:00:00.0000000 Joe 2018-04-15 00:00:00.0000000
Test.cs
public partial class Test
{
public DateTime CalendarDate { get; set; }
public string Name { get; set; }
public DateTime BirthDate { get; set; }
}
Context.cs
modelBuilder.Entity<Test>(entity =>
{
entity.HasKey(e => new { e.CalendarDate });
entity.Property(e => e.CalendarDate).HasColumnType("datetime2(7)");
entity.Property(e => e.Name).HasMaxLength(50);
entity.Property(e => e.BirthDate).HasColumnType("datetime2(7)");
});
Scaffolded controller and views were then created. Note: No other formatting has been added.
Note: CalendarDate (the key) has been added to Index View for clarity.
Index Display:
Index
CalendarDate Name BirthDate
15/04/2018 12:00:00 AM Joe 15/04/2018 12:00:00 AM Edit |Details|Delete
Note in Index View
<a asp-action="Edit" asp-route-id="@item.CalendarDate">Edit</a>
does not find record but
@Html.ActionLink("Edit", "Edit", new { CalendarDate = item.CalendarDate })
does if id is changed to CalendarDate in controller.
Edit Display:
CalendarDate 04/15/2018 00:00:00 Name Joe BirthDate 2018-04-15T00:00:00.000
Note: CalendarDate (the key) has been added to Edit View for clarity.
Also note: Format displays as MM/dd/yyyy. Update fails.
Create works. If I create 01/01/2018 and then Edit, the Edit update works.
IE only works if day and month are equal.
Does anyone have a sample of a working function where the Key is a Datetime field please?