EF 6.0 DBSet.AddRange() - How to skip individual entity errors

addrange c# entity-framework entity-framework-6

Question

I am trying to push 100 Product entities created dynamically, using DBSet.AddRange().

If for example, 1st Product entity has some data issues and throws exception during Commit(), all remaining 99 product entities also not going to save.

Is it possible to skip corrupted entities only so that other entities can be saved using DBSet.AddRange() ?

1
0
4/11/2016 9:39:49 AM

Accepted Answer

You cannot do this with EF, you have to change your logic and validate the entities yourself before adding them to the EF context. Alternatively, you have to add them individually and commit after each one, but that will be much less efficient.

2
4/11/2016 9:08:52 AM


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