I check the source code of Entity Framework. I found that the reason of bug is about Validate
method of ValidationAttributeValidator
class of EF assembly.
This method is call when a entity going to validate. And it will check any Attribute
of Property
. However, RequiredAttribute
is not belong to EF assembly. GetValidationResult
method of RequiredAttribute
will not care about lazy loading of EF.
So, I think the solution is change the code of Validate
method of ValidationAttributeValidator
class. Ignore it if Attribute
is RequiredAttribute
and do something to validate property with lazy loading.