Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm currently using a control with an Edit view action that looks like this:
C#
public async Task<ActionResult> Edit([Bind(Include = "Id,Name,IsSubscribedToNewsLetter,Birthdate,MembershipTypeId")] Customer customer)
{
    if (ModelState.IsValid)
    {
        db.Entry(customer).State = EntityState.Modified;
        await db.SaveChangesAsync();
        return RedirectToAction("Index");
    }
    ViewBag.MembershipTypeId = new SelectList(db.MembershipTypes, "Id", "Id", customer.MembershipTypeId);
    return View(customer);
}

Here is the error:
The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value.

The statement has been terminated.

It appears as if DateTime2 is being used in the Edit view but when attempting to save, since the field in the table is defined as a simple DateTime, that it cannot make the conversion.

Is there some way using CodeFirst migrations to specify that a field is actually DateTime2 instead of DateTime (in the Model definition ... something using Data Annotations maybe?

Thanks,

C. T.

What I have tried:

What I have tried is specified above ...
Posted
Updated 22-Mar-19 5:28am

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900