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

Migrations do not fully qualify types, resulting in compile errors #25933

Closed
tpodolak opened this issue Sep 8, 2021 · 1 comment
Closed

Migrations do not fully qualify types, resulting in compile errors #25933

tpodolak opened this issue Sep 8, 2021 · 1 comment
Labels
closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. customer-reported

Comments

@tpodolak
Copy link

tpodolak commented Sep 8, 2021

File a bug

dotnet ef migrations add MigrationName generates code without fully qualified class names when referencing properties

modelBuilder.Entity("TestProject1.Models.Products.Product", b =>
                {
                    b.Property<string>("Id")
                        .HasColumnType("text");

                    b.Property<Label>("Label") <--  CS0104
                        .HasColumnType("jsonb");

                    b.HasKey("Id");

                    b.ToTable("Product");
                });

resulting in CS0104 compiler error in snapshot,migration and Migration.Designer.cs. That is happening the moment we have same class name in different namespaces (with same root namespace) see sample code below. This is very inconvenient as the only workaround I found is to rename classes - which result in prefixed names eg Label -> VariantLabel
This looks similar to #25523, however newest preview version of EF Core/EF Core Tools still generates conflicting code in migrations.

As far as I can tell, bug is located here

var propertyBuilderName = $"{entityTypeBuilderName}.Property<{Code.Reference(clrType)}>({Code.Literal(property.Name)})";

as Code.Reference(clrType) is called without fullName flag

Include your code

Sample project attached TestProject1.zip

Include stack traces

N/A

Include verbose output

dotnet ef migrations add Init --verbose
Using project '/media/tpodolak/b43e2cf3-1a1e-436b-96d5-25448f19a97c/home/tpodolak/Code/TestProject1/TestProject1/TestProject1.csproj'.
Using startup project '/media/tpodolak/b43e2cf3-1a1e-436b-96d5-25448f19a97c/home/tpodolak/Code/TestProject1/TestProject1/TestProject1.csproj'.
Writing '/media/tpodolak/b43e2cf3-1a1e-436b-96d5-25448f19a97c/home/tpodolak/Code/TestProject1/TestProject1/obj/TestProject1.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=/tmp/tmpeI2Ypu.tmp /verbosity:quiet /nologo /media/tpodolak/b43e2cf3-1a1e-436b-96d5-25448f19a97c/home/tpodolak/Code/TestProject1/TestProject1/TestProject1.csproj
Writing '/media/tpodolak/b43e2cf3-1a1e-436b-96d5-25448f19a97c/home/tpodolak/Code/TestProject1/TestProject1/obj/TestProject1.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=/tmp/tmp6s7fdL.tmp /verbosity:quiet /nologo /media/tpodolak/b43e2cf3-1a1e-436b-96d5-25448f19a97c/home/tpodolak/Code/TestProject1/TestProject1/TestProject1.csproj
Build started...
dotnet build /media/tpodolak/b43e2cf3-1a1e-436b-96d5-25448f19a97c/home/tpodolak/Code/TestProject1/TestProject1/TestProject1.csproj /verbosity:quiet /nologo

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.90
Build succeeded.
dotnet exec --depsfile /media/tpodolak/b43e2cf3-1a1e-436b-96d5-25448f19a97c/home/tpodolak/Code/TestProject1/TestProject1/bin/Debug/net5.0/TestProject1.deps.json --additionalprobingpath /home/tpodolak/.nuget/packages --additionalprobingpath /usr/share/dotnet/sdk/NuGetFallbackFolder --runtimeconfig /media/tpodolak/b43e2cf3-1a1e-436b-96d5-25448f19a97c/home/tpodolak/Code/TestProject1/TestProject1/bin/Debug/net5.0/TestProject1.runtimeconfig.json /home/tpodolak/.dotnet/tools/.store/dotnet-ef/6.0.0-preview.7.21378.4/dotnet-ef/6.0.0-preview.7.21378.4/tools/netcoreapp3.1/any/tools/netcoreapp2.0/any/ef.dll migrations add Init --assembly /media/tpodolak/b43e2cf3-1a1e-436b-96d5-25448f19a97c/home/tpodolak/Code/TestProject1/TestProject1/bin/Debug/net5.0/TestProject1.dll --project /media/tpodolak/b43e2cf3-1a1e-436b-96d5-25448f19a97c/home/tpodolak/Code/TestProject1/TestProject1/TestProject1.csproj --startup-assembly /media/tpodolak/b43e2cf3-1a1e-436b-96d5-25448f19a97c/home/tpodolak/Code/TestProject1/TestProject1/bin/Debug/net5.0/TestProject1.dll --startup-project /media/tpodolak/b43e2cf3-1a1e-436b-96d5-25448f19a97c/home/tpodolak/Code/TestProject1/TestProject1/TestProject1.csproj --project-dir /media/tpodolak/b43e2cf3-1a1e-436b-96d5-25448f19a97c/home/tpodolak/Code/TestProject1/TestProject1/ --root-namespace TestProject1 --language C# --working-dir /media/tpodolak/b43e2cf3-1a1e-436b-96d5-25448f19a97c/home/tpodolak/Code/TestProject1/TestProject1 --verbose
Using assembly 'TestProject1'.
Using startup assembly 'TestProject1'.
Using application base '/media/tpodolak/b43e2cf3-1a1e-436b-96d5-25448f19a97c/home/tpodolak/Code/TestProject1/TestProject1/bin/Debug/net5.0'.
Using working directory '/media/tpodolak/b43e2cf3-1a1e-436b-96d5-25448f19a97c/home/tpodolak/Code/TestProject1/TestProject1'.
Using root namespace 'TestProject1'.
Using project directory '/media/tpodolak/b43e2cf3-1a1e-436b-96d5-25448f19a97c/home/tpodolak/Code/TestProject1/TestProject1/'.
Remaining arguments: .
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider in assembly 'TestProject1'...
Finding Microsoft.Extensions.Hosting service provider...
No static method 'CreateHostBuilder(string[])' was found on class 'Program'.
No application service provider was found.
Finding DbContext classes in the project...
Found DbContext 'MyDataContext'.
Using context 'MyDataContext'.
Finding design-time services for provider 'Npgsql.EntityFrameworkCore.PostgreSQL'...
Using design-time services from provider 'Npgsql.EntityFrameworkCore.PostgreSQL'.
Finding design-time services referenced by assembly 'TestProject1'...
Finding design-time services referenced by assembly 'TestProject1'...
No referenced design-time services were found.
Finding IDesignTimeServices implementations in assembly 'TestProject1'...
No design-time services were found.
DetectChanges starting for 'MyDataContext'.
DetectChanges completed for 'MyDataContext'.
Writing migration to '/media/tpodolak/b43e2cf3-1a1e-436b-96d5-25448f19a97c/home/tpodolak/Code/TestProject1/TestProject1/Migrations/20210908134406_Init.cs'.
Writing model snapshot to '/media/tpodolak/b43e2cf3-1a1e-436b-96d5-25448f19a97c/home/tpodolak/Code/TestProject1/TestProject1/Migrations/MyDataContextModelSnapshot.cs'.
'MyDataContext' disposed.
Done. To undo this action, use 'ef migrations remove'


Include provider and version information

EF Core version: 5.0.9
EF Tools: both 5.x and 6.x generates invalid code
Database provider: Npgsql.EntityFrameworkCore.PostgreSQL
Target framework: .NET 5.0
Operating system:
IDE: Rider

@AndriySvyryd
Copy link
Member

Detecting cases like this is out of scope for EF. However in 6.0 you will be able to specify which types should be fully qualified by overriding CSharpHelper.ShouldUseFullName using IDesignTimeServices

@AndriySvyryd AndriySvyryd added the closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. label Sep 16, 2021
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. customer-reported
Projects
None yet
Development

No branches or pull requests

3 participants