model-building
Model Building, Conventions & Initialization
Covers model construction (conventions, fluent API, metadata hierarchy) and model initialization (runtime annotation propagation, compiled model filtering).
Convention System
ConventionSet (src/EFCore/Metadata/Conventions/ConventionSet.cs) holds List<I*Convention> for every metadata event. Key conventions in src/EFCore/Metadata/Conventions/:
DbSetFindingConvention— discovers entities fromDbSet<T>PropertyDiscoveryConvention— discovers properties from CLR typesKeyDiscoveryConvention— finds PKs (Id,TypeId)RelationshipDiscoveryConvention— infers FKs from navigationsRuntimeModelConvention— creates optimizedRuntimeModelfrom mutable model
Override ConfigureConventions(ModelConfigurationBuilder) to add/remove conventions.
Convention fixes must preserve dispatcher behavior and ambiguity information. For inverse-navigation attributes, do not solve recursion by permanently ignoring an ambiguous navigation: removing one candidate can make another ambiguity appear unique and configure the wrong relationship. InversePropertyAttributeConvention records inverse candidates and uses AddInverseNavigation, TryRemoveIfAmbiguous, and FindAmbiguousInverse while still allowing convention processing to continue.
Test the state transitions, not only the initially ambiguous model: first verify that multiple interacting candidates configure no relationship; then genuinely remove ambiguity both by ignoring/removing one competing navigation and by removing a competing entity type, and verify that the remaining inverse relationship is configured. These cases distinguish candidate bookkeeping from a permanent-ignore workaround.