0

I build a simple model. The reason StartDate is DateTime2 is because previously it gave me an error when i tried to have the DateTime.

 public class Auction
{
    [Key]
    public string Id { get; set; }
    [Required]
    public string Title { get; set; }
    public string Description { get; set; }
    [Column(TypeName = "DateTime2")]
    [Display(Name = "StartTime")]
    public DateTime StartTime { get; set; }
    [Column(TypeName = "DateTime2")]

    public DateTime EndTime { get; set; }
    public int StartPrice { get; set; }
    public int CurrentPrice { get; set; }
    public string category { get; set; }

    public virtual Collection<Bid> Bids { get; private set; }

    public int BidCount
    {
        get { return Bids.Count; }
    }

    public Auction()
    {
        Bids = new Collection<Bid>();

    }

and i created a create() function in controller.

     [HttpPost]
     public ActionResult create(Auction auction)
     {
         var categoryList = new SelectList(new[] { "auto", "elec", "games", "Home" });
         ViewBag.categoryList = categoryList;
         auction.StartTime= DateTime.Now;
         auction.EndTime = DateTime.Now.AddDays(7);

          if (ModelState.IsValid)
         {
             //Save the form
              var db = new AuctionsDataContext();
             db.Auctions.Add(auction);
             db.SaveChanges();

             return RedirectToAction("Index");

         }
         return View();

     }

I get this error when i try to save changes:

 Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.Entity.Validation.DbEntityValidationException: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
4

0 に答える 0