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

RevEng: nameof syntax error #16083

Closed
Hursev opened this issue Jun 13, 2019 · 1 comment · Fixed by #16918
Closed

RevEng: nameof syntax error #16083

Hursev opened this issue Jun 13, 2019 · 1 comment · Fixed by #16918
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@Hursev
Copy link

Hursev commented Jun 13, 2019

Describe what is not working as expected.
I have a table in Azure SQL server like

CREATE TABLE [dbo].[ConfigMetaObject] (
    [ConfigFileId] INT NOT NULL,
	...
    CONSTRAINT [FK_ConfigMetaObject_ConfigFile] FOREIGN KEY ([ConfigFileId]) REFERENCES [dbo].[ConfigFile] ([Id]) ON DELETE CASCADE,
	...
);

When I [re]generate the model files using

Scaffold-DbContext "..." Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Force -DataAnnotations

The generated class looks like
Using preview 5:

public partial class ConfigMetaObject
{
	public int ConfigFileId { get; set; }
	...	
	[ForeignKey("ConfigFileId")]
	[InverseProperty("ConfigMetaObject")]
	public virtual ConfigFile ConfigFile { get; set; }
	...
}

Which works OK.

But using preview 6:

public partial class ConfigMetaObject
{
	public int ConfigFileId { get; set; }
	...	
	[ForeignKey(nameof(ConfigFileId))]
	[InverseProperty(nameof(ConfigFile.ConfigMetaObject))]
	public virtual ConfigFile ConfigFile { get; set; }
	...
}

The problem is that both the class name (ConfigFile) and the member name are ConfigFile and as result when the compiler see the 'ConfigFile' in

[InverseProperty(nameof(ConfigFile.ConfigMetaObject))]

it thinks it is the member variable, not the class.

The solution, as I see, will be in these cases to prefix the class name with the namespace. Like

[InverseProperty(nameof(myNamespace.ConfigFile.ConfigMetaObject))]

Further technical details

EF Core version: 3.0.0-preview6.19304.10
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
IDE: Visual Studio 2019 preview 2

@Hursev Hursev changed the title Scaffold-DbContext broken when -DataAnnotations is used Scaffold-DbContext broken when -DataAnnotations is used in preview 6 Jun 13, 2019
@bricelam bricelam self-assigned this Jun 13, 2019
@ajcvickers ajcvickers added this to the 3.0.0 milestone Jun 14, 2019
@bricelam bricelam changed the title Scaffold-DbContext broken when -DataAnnotations is used in preview 6 RevEng: nameof syntax error Jun 20, 2019
@ajcvickers ajcvickers modified the milestones: 3.0.0, 3.0.0-preview7 Jul 2, 2019
@bricelam bricelam added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Aug 2, 2019
@ajcvickers ajcvickers modified the milestones: 3.0.0, 3.0.0-preview9 Aug 21, 2019
@ajcvickers ajcvickers modified the milestones: 3.0.0-preview9, 3.0.0 Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants