-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IAnnotatable.FindAnnotation does not find annotations recursively #20374
Comments
A little correction, |
@obohaciak This is currently by-design. Can you explain a bit more about why you need them to be recursive? |
The difference between properties, navigations and annotations is that there can only be 1 property or navigation with the same name in a hierarchy, but there can be more than 1 annotation with the same name. |
@ajcvickers Of course, I'll try to explain. I was inspired by an example given by @rowanmiller in #7586 in which he shows how to use custom annotations to add support for read-only entities. My case is similar - track entities strongly related to each other, much like a composition relationship. E.g. an entity EnginePart exists within and cannot exist without an Engine. However Engine is an abstract type, a base type of larger type hierarchy with derived types like CarEngine or PlaneEngine. The custom annotation may exist on any level in the hierarchy. I therefore need to walk the inheritance chain and ask each entity type if it defines the annotation. I hope that that makes sense. I understand though that as @AndriySvyryd noted, an annotation can be defined multiple times in the type hierarchy and the result of |
@obohaciak Thanks for additional info. Closing this as by-design for now. |
When calling
FindAnnotation
on a derived entity type, the annotations declared on the base type are not returned.Steps to reproduce
Consider following model:
Searching for the annotation on derived type:
Whereas, searching for the annotation on base type:
If we compare it analogous
FindProperty
, andFindDeclaredProperty
, perhaps thisFindAnnotation
should have beenFindDeclaredAnnotation
instead to highlight the fact it searches the given type only whereas "FindAnnotation" implies that it works recursively.It would be a (limited?) breaking change though, so perhaps something for a major release like .NET 5?
Further technical details
EF Core version: 3.1.1
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET Core 3.1
Operating system: Windows 10.0.18363.720
IDE: Visual Studio 2019 Enterprise 16.5.0
The text was updated successfully, but these errors were encountered: