0

My project is web apllication on ASP.NET MVC 6 and basicaly I have a realy weird problem.

This is the code:

await Dashboards.UpdateReward(dashboard);
await Lessons.Update(lesson);

methods don't do anything specific but save modified states to database.

Here is what the problem is. When I start application normally and run through this part of the code it throws error:

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

But here is the tricky part when I debug it and go step by step it works just fine without any error.

Filburt
  • 17,626
  • 12
  • 64
  • 115
sseles
  • 1
  • Is there an dependency between "Dashboards" and "Lessons"? – Luc Aug 24 '15 at 18:49
  • Probably your datetime fields are not set. – DarthVader Aug 24 '15 at 19:08
  • If you use **Entity Framework** you can have a look at my answer on [Solution for “Validation failed for one or more entities. See 'EntityValidationErrors' property for more details](http://stackoverflow.com/questions/21486072/solution-for-validation-failed-for-one-or-more-entities-see-entityvalidatione/29031857#29031857). Hope this helps... – Murat Yıldız Jan 26 '16 at 23:15

2 Answers2

0

You may want to take a look at this to find more information about your exception:

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

Community
  • 1
  • 1
AnotherDeveloper
  • 1,242
  • 1
  • 15
  • 36
0

Thank you for your help. It would seem that the problem was in dashboard model. Lazzy loading didnt load my User property and since it is foreign key it can not be null value.

    [Key, ForeignKey("User")]
    public string UserId { get; set; }

    //Gemification
    public int Level { get; set; }
    public int Experience { get; set; }
    public int Yens { get; set; }

    //Application
    [Column(TypeName = "datetime2")]
    public DateTime Created { get; set; }
    [Column(TypeName = "datetime2")]
    public DateTime Updated { get; set; }
    public string CreatedBy { get; set; }
    public string UpdatedBy { get; set; }

    public virtual ICollection<Lesson> Lessons { get; set; }
    public virtual ICollection<OwnedGroup> OwnedGroups { get; set; }
    [Required]
    public virtual ApplicationUser User { get; set; }

Any way thank you for your help.

sseles
  • 1