-
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
Add sugar to allow opt-in mapping for properties/relationships/etc. #16009
Comments
This would be possible by removing some of the default conventions, tracked in #214 Linking the docs issue: https://github.com/aspnet/EntityFramework.Docs/issues/1516 |
@AndriySvyryd - im not sure I understand. I'm looking for something I can decorate a class and members with (either by fluent or preferably, attributes ) to instruct EF on the classes and properties it should be using. Is there really nothing available in EF6 or EFCore for this? |
@StingyJack There's no specific switch for this. foreach (var entityType in modelBuilder.Model.GetEntityTypes())
{
var entityTypeBuilder = modelBuilder.Entity(entityType.ClrType);
foreach (var navigation in entityType.GetNavigations())
{
entityTypeBuilder.Ignore(navigation.Name);
}
foreach (var property in entityType.GetProperties())
{
entityTypeBuilder.Ignore(property.Name);
}
} |
That seems like a lot to have to do when attributes like |
Putting this on the backlog to consider adding sugar that would remove some conventions and set EF Core to use opt-in mapping. Exactly what this means remains to be determined. For example, does mapping a navigation property imply FK convention mapping or not? |
It would if you decorated it with something like EF having this would mean it could play well with others instead of being the DAL bully or separatist. |
If I have a class that is to be used with EF as a complete and correct table mapping. This class is generated from some description elsewhere.
This class is intended to be extended with some additional properties that do not require persistence and a few methods.
When I try to save an instance of Car, EF errors about MaxSpeed not being mapped. The advice most commonly given is to either add
[NotMapped]
to MaxSpeed, or to create a second Car class and add the MaxSpeed property to that and remap the EF object to the new Car on Gets and back to the EF object on Saves. The remapping is not preferable and is not an option in the scope of this post.Adding
[NotMapped]
to every field not part of the entity is also ripe with chances for bugs to happen.Is there any way to "Opt In" an object and specific properties so that EF knows which are eligible for its scope?
The text was updated successfully, but these errors were encountered: