0

I am working on MVC application, there I am trying to update one table during edit operation. I am getting the following error.

Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.

I searched no clue. Here is my code, any help please?

var hoteling = context.Hoteling.FirstOrDefault(h => h.HotelingId == modelData.HotelingId);

if (hoteling != null)
{
     hoteling.BookedBy = (string)Session["UserName"];
     hoteling.BookingType = Convert.ToInt32(modelData.BookingType);
     hoteling.Description = modelData.Description;
     hoteling.StartDate = modelData.StartDate;
     hoteling.EndDate = modelData.EndDate;
     hoteling.StartTime = modelData.StartTime;
     hoteling.EndTime = modelData.EndTime;
     hoteling.WorkSpaceRefId = modelData.WorkSpaceRefId;
     hoteling.ProjectId = 1;
     hoteling.RepeatDay = modelData.RepeatDay;
     hoteling.RepeatType = modelData.RepeatType;
     context.SaveChanges();
}
Yuliam Chandra
  • 14,494
  • 12
  • 52
  • 67
user1557020
  • 301
  • 3
  • 6
  • 20
  • 3
    That's obvious, there is a fail validation, wrap the code with [this](http://stackoverflow.com/questions/7795300/validation-failed-for-one-or-more-entities-see-entityvalidationerrors-propert) and see what's the error – Yuliam Chandra Aug 20 '14 at 07:40
  • 2
    @YuliamChandra Super useful tip, I really like the method. Honestly, I cannot understand why such a method is not used to display a more meaningful error to the deeloper – Christian Sauer Aug 20 '14 at 07:53
  • im sorry yliam i didnt understand what you are telling. How to do that please? – user1557020 Aug 20 '14 at 08:19
  • @user1557020, wrap the `context.SaveChanges();` code just like in the link, click [this link](http://stackoverflow.com/a/7798264/968303) – Yuliam Chandra Aug 20 '14 at 08:27
  • i have done it before its is telling the cell is empty. what it mean – user1557020 Aug 20 '14 at 08:39
  • it means that the cell has to have a value, you might set the property as `[Required]`. Could you give list of properties that caused the error, from the link I gave, you can see it while debugging in `ve.PropertyName, ve.ErrorMessage`, also show your hoteling class.. – Yuliam Chandra Aug 20 '14 at 10:09
  • It says "See 'EntityValidationErrors' property for more details." It doesn't look like you did this because these errors *always* tell you what's wrong. – Gert Arnold Aug 20 '14 at 19:48

0 Answers0