Code inspection issues with Entity Framework entities


I am currently in the evaluation of ReSharper 8.2.1 C# Edition. I have a project in my solution containing entity framework entities classes.
Since the properties mapped in the classes are virtual, I am getting the warning that class has virtual members with no inheritors on almost all my entities. Actually, the entity framework itself creates proxy classes inheriting from my entities and overrides my virtual members.
The other warning I get on almost all properties is that they can be made protected (or the setter can be made protected). However, entity framework ignores protected members by default unless I use fluid API.

Currently I workaround this by adding ReSharper disable once ClassWithVirtualMembersNeverInherited.Global comment in code for every class, and UsedImplicitly attribute on all properties. But this is an ugly solution in my opionion. Is there a better way to mark the class as a entity framework entity to silence these warnings?

Also if I have a class whose members are set using MVC model binder, and never directly in code, is there a way to tell reshaper to not warn me that setter should be protected?

Thanks a lot in advance.

Comment actions Permalink

warnings on properties' getters and setters can be avoided by marking containing classes with "UsedImplicitly(ImplicitUseTargetFlags.WithMembers)" attribute.
Unfortunately, there is no way to avoid warnings "ClassWithVirtualMembersNeverInherited" except setting its severity to "NONE". I've created bug fot this, feel free to comment there:

Comment actions Permalink


Thanks a lot for your reply.
I have all my entity framework entities in a single project in my solution and that project contains no other classes. Can I set the severity of ClassWithVirtualMembersNeverInherited to NONE in the scope of that project only and not in other projects within the same solution?

Sorry if the answer to the question is obvious, but when I tried it showed I am allowed to save the scope setting to the solution settings file only.

Comment actions Permalink

there is no easy way to set settings for one project from solution. You can try this workaround:


Please sign in to leave a comment.