Validating entities before saving and removing from context

c# entity-framework

Question

Can I validate the entities I've previously put to the context before making a call?SaveChanges and eliminate the invalid ones to prevent me from receiving theEntityValidationErrors a save?

I have a list of roughly 3000 entities, some of which have faulty data that prevents me from saving any further entities. Instead of saving each object separately, I would prefer to ignore any that have problems.

In my search for a fix, I discovered that the validation may be turned off. I'd do it if I did itSaveChanges Save the others and disregard the invalid ones?

Context.Configuration.ValidateOnSaveEnabled = false;

However, I would much rather call a function to activate entity validation and remove it from the environment. Perhaps I could validate an entity before adding it to the context? Better still would be this.

1
7
2/15/2016 8:12:51 AM

Accepted Answer

ZZZ_tmp
7
2/15/2016 8:48:23 AM

Popular Answer

ZZZ_tmp


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow