dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.61k stars 3.14k forks source link

When the `PropertyDiscoveryConvention` is removed, then also skip call to `ValidatePropertyMapping(model, logger)` in ModelValidator #33825

Open RDoser opened 3 months ago

RDoser commented 3 months ago

Converting a Database First EF6 project to EF Core. The existing database is the arbiter of truth, NOT the POCOs. Model is fully defined using Fluent API and so have removed the PropertyDiscoveryConvention in ConfigureConventions() but ModelValidator insists that every read/write property be mapped or tagged with Ignore or [NotMapped] attribute. POCOs contain literally thousands of such properties used for functional or front end purposes that have nothing to do with the model/database (for example, hundreds of Flag type enums associated with read/write boolean properties).

Only run the ValidatePropertyMapping(model, logger) method in ModelValidator if PropertyDiscoveryConvention is present in the Model Builder's Conventions collection.

ajcvickers commented 3 months ago

I don't believe this is the correct approach to take. The model validator should still validate property mappings, but it could be easier to override that behavior--this is tracked by #15660.

See also the example of changing the property mapping convention in the docs: Example: Opt-in property mapping

RDoser commented 3 months ago

@ajcvickers Thanks. https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-7.0/whatsnew#replacing-an-existing-convention seems to be exactly what I have been looking for for the past month. Not sure why this was so hard to find, but THANK YOU!

ajcvickers commented 3 months ago

@RDoser No. Every property is configured as mapped or not mapped.