Entity Framework SaveChanges error details

后端 未结 5 1292
攒了一身酷
攒了一身酷 2021-02-18 14:35

When saving changes with SaveChanges on a data context is there a way to determine which Entity causes an error? For example, sometimes I\'ll forget to assign a da

5条回答
  •  既然无缘
    2021-02-18 15:11

    One option is to handle the ObjectContext.SavingChanges Event, which gives you a chance to perform validation on entities before the changes are saved and even cancel the save if necessary. This way you can make sure any non-nullable properties are set before trying to save changes, and avoid having to rely on exception handling.

提交回复
热议问题