EF Core State Validation
Introduction How many times have you tried to save changes to your context only to get an exception about validation problems, like a required property being null ? I certainly have, and because of this, I came up with a solution to figure out what is happening. I will also provide some possible solutions for the problem of fully validating an entity using the Data Annotations API (a post on general validation with Data Annotations here ). State Validation All the entities that are currently tracked by a DbContext have some state known to the context. This state includes: The entity's state ( State ) in regards to persistence ( Modified , Added , Deleted , Unchanged ) Each property's values ( Property ), both current ( Current ) and original ( Original ) The entity itself ( Entity ) Any navigation properties ( References , Navigations ) So, we can iterate through each tracked entry by means of the Entries , Entries<T> , or Entry methods: var entity = ...; var ent...