The conversion of a datetime2 data type to a datetime data type Error

后端 未结 9 1595
慢半拍i
慢半拍i 2020-12-30 08:45

I have a controller:

[HttpPost]
public ActionResult Create(Auction auction)
{
    var db = new EbuyDataContext();
    db.Auctions.Add(auction);
    db.SaveCh         


        
9条回答
  •  青春惊慌失措
    2020-12-30 09:05

    The error is because you haven't actually set those values correctly, make sure you set them depending on your applications locale. (e.g. dd/mm/yyyy for en-GB, mm/dd/yyyy for en-US).

    It also looks like your database has been set up to use a datetime2 column and not a datetime column.

    You can either:

    A) Modify the database to change the type from datetime2 to datetime

    B) Change the types in your Model to be datetime2, by doing:

    [Column(TypeName = "DateTime2")]
    public DateTime StartTime { get; set; }
    
    [Column(TypeName = "DateTime2")]
    public DateTime EndTime { get; set; }
    

提交回复
热议问题