Skip to content
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

Log a warning when Ignore is called on an explicitly configured property or type #12082

Closed
Tarig0 opened this issue May 21, 2018 · 5 comments · Fixed by #29926
Closed

Log a warning when Ignore is called on an explicitly configured property or type #12082

Tarig0 opened this issue May 21, 2018 · 5 comments · Fixed by #29926
Labels
area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported punted-for-2.2 punted-for-3.0 punted-for-6.0 punted-for-7.0 Originally planned for the EF Core 7.0 (EF7) release, but moved out due to resource constraints. type-bug
Milestone

Comments

@Tarig0
Copy link

Tarig0 commented May 21, 2018

When ignoring a property that is explicitly used in a key throw an error

Steps to reproduce

modelBuilder.Entity<Counter>().HasAlternateKey(c => new { c.StyleKey, c.IsTest, c.Discriminator });
            modelBuilder.Entity<Counter>().Ignore(c => c.Discriminator);

Further technical details

EF Core version: 2.1.0 rc1 final
Database Provider: Microsoft.EntityFrameworkCore.Sqlite
Operating system: Win10
IDE: Visual Studio 2017 15.7.1

@ajcvickers
Copy link
Contributor

@Tarig0 Why are you both referencing and ignoring the property explicitly?

@Tarig0
Copy link
Author

Tarig0 commented May 21, 2018

Because I wasn't ignoring the property when I was using the value converter feature, then switched to a private store property, and didn't update the key.

@AndriySvyryd
Copy link
Member

Unfortunately if Ignore threw an exception in this case then it would be impossible to remove that property from the model as there's no API for removing keys. But we could log a warning.

@Tarig0
Copy link
Author

Tarig0 commented Jul 17, 2018

I think the issue I'm seeing is that the Model is invalid so the program shouldn't be able to continue with the configuration. Not that I want the model to remove the alternate key, but to say hey this alternate key is not valid bad program.

modelBuilder.Entity<Counter>().HasAlternateKey(c => new { c.StyleKey, c.IsTest, c.Discriminator }); //This should be c.StrDiscriminator
            modelBuilder.Entity<Counter>().Ignore(c => c.Discriminator);

@AndriySvyryd
Copy link
Member

@Tarig0 I understand that in your case the model configuration is contradicting and doesn't produce the expected model. But Ignore is also used to remove previous configuration. For example that 'HasAlternateKey' call could be in the base context type that you are deriving from and you can't change that code, so calling Ignore would be the only way to remove that key.

@AndriySvyryd AndriySvyryd changed the title Ignore should invalidate model if property is explicitly used else where Log a warning when Ignore is called on an explicitly configured property or type Jul 17, 2018
@ajcvickers ajcvickers modified the milestones: 2.2.0-preview2, 2.2.0 Sep 11, 2018
@ajcvickers ajcvickers modified the milestones: 2.2.0, 3.0.0 Oct 1, 2018
@ajcvickers ajcvickers added help wanted This issue involves technologies where we are not experts. Expert help would be appreciated. and removed size~1-day labels Nov 7, 2018
@divega divega added good first issue This issue should be relatively straightforward to fix. help wanted This issue involves technologies where we are not experts. Expert help would be appreciated. and removed help wanted This issue involves technologies where we are not experts. Expert help would be appreciated. good first issue This issue should be relatively straightforward to fix. labels May 31, 2019
@divega divega modified the milestones: 3.0.0, Backlog Jun 20, 2019
@ajcvickers ajcvickers modified the milestones: 6.0.0, Backlog Oct 1, 2021
@ajcvickers ajcvickers modified the milestones: Backlog, 7.0.0 Nov 10, 2021
@ajcvickers ajcvickers added propose-close propose-punt punted-for-7.0 Originally planned for the EF Core 7.0 (EF7) release, but moved out due to resource constraints. and removed propose-close propose-punt labels Apr 22, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0, Backlog Apr 23, 2022
@ajcvickers ajcvickers modified the milestone: Backlog Dec 4, 2022
@ajcvickers ajcvickers modified the milestones: Backlog, 8.0.0 Dec 23, 2022
@ajcvickers ajcvickers added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed poachable labels Dec 23, 2022
ajcvickers added a commit that referenced this issue Dec 23, 2022
ajcvickers added a commit that referenced this issue Dec 23, 2022
@ajcvickers ajcvickers modified the milestones: 8.0.0, 8.0.0-preview1 Jan 29, 2023
@ajcvickers ajcvickers modified the milestones: 8.0.0-preview1, 8.0.0 Nov 14, 2023
@ajcvickers ajcvickers removed their assignment Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported punted-for-2.2 punted-for-3.0 punted-for-6.0 punted-for-7.0 Originally planned for the EF Core 7.0 (EF7) release, but moved out due to resource constraints. type-bug
Projects
None yet
4 participants