-
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
DbContext scaffolding creates reference error CS0120 in nameof() for InverseProperty in certain conditions #26588
Comments
Note for triage: regression in 6.0. 5.0 generates: [InverseProperty("MA")]
public virtual ICollection<MFMAMA> MFMAMA { get; set; } While 6.0 generates: [InverseProperty(nameof(MFMA.MA))]
public virtual ICollection<MFMA> MFMA { get; set; } |
Notes from triage:
|
I would prefer this as a patch but since this is a compile time issue I think we could live with a workaround for a year if it is too much effort to fix it now |
Scoping causes clash in names. Resolves #26588
Scoping causes clash in names. Resolves #26588
@ajcvickers I'd love to have this as a patch to 6 since manually patching the generated files (or adding a search/replace process) is cumbersome and error-prone. Nameof is a great feature, but in generated code it's less valuable since you won't refactor generated code (which I understand is why you revert the changes, good). |
Note from triage: patch this in 6.0. |
Scoping causes clash in names. Resolves #26588
Scoping causes clash in names. Resolves #26588
when table names in n:m relations meet certain criteria, the below code is created by dbScaffold (DDL statements at the bottom)
The problem is line
[InverseProperty(nameof(MFMA.MA))]
which wants to reference the class called MFMA but actually references the next line's Icollection. this creates compiler error CS0120 "An object reference is required for the non-static field, method, or property 'MFMA.MA'"The solution is to qualify the MFMA like so
[InverseProperty(nameof(database.MFMA.MA))]
I could imagine the issue comes from the naming pattern that one table ends with the other tables names but that's just a guess.
Statement used for scaffolding
DDL-Statements:
provider and version information
EF Core version: 6.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: NET 6.0
Operating system:
IDE: (e.g. Visual Studio 20202 current)
The text was updated successfully, but these errors were encountered: