We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
After creating a DbContext and an entity within the Program.cs file, calling add-migration produces a migration file with syntax error:
Program.cs
add-migration
The produced migration looks like this and everything is okay in it (it was generated correctly) except for line 1 where it has an empty using:
using
using ; using Microsoft.EntityFrameworkCore.Migrations; using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable namespace WebApplication1.Migrations { /// <inheritdoc /> public partial class test : Migration { // protected override void Up() omitted for brevity // protected override void Down() omitted for brevity } }
Program.cs:
```csharp using Microsoft.EntityFrameworkCore; using Npgsql; var builder = WebApplication.CreateBuilder(args); var dataSource = new NpgsqlDataSourceBuilder(builder.Configuration.GetConnectionString("Database")) .EnableDynamicJson().Build(); builder.Services.AddDbContext<MyDbContext>(options => options.UseNpgsql(dataSource)); var app = builder.Build(); //app.MapGet("/", (MyDbContext context) => ... //app.MapGet("/add", (MyDbContext context) => ... //app.MapGet("/update", (MyDbContext context) => ... app.Run(); public class Person { public int Id { get; set; } public required string Name { get; set; } public List<Address> Addresses { get; set; } = []; } public class Address { public int Id { get; set; } public int PersonId { get; set; } public virtual Person? Person { get; set; } public Metadata Metadata { get; set; } } public class Metadata { public int Age { get; set; } public string? Interest { get; set; } } public class MyDbContext(DbContextOptions<MyDbContext> options) : DbContext(options) { public DbSet<Person> People { get; set; } public DbSet<Address> Addresses { get; set; } protected override void OnModelCreating(ModelBuilder builder) { base.OnModelCreating(builder); builder.Entity<Address>() .Property(e => e.Metadata) .HasColumnType("jsonb"); } }
The project file:
<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>net8.0</TargetFramework> <Nullable>enable</Nullable> <ImplicitUsings>enable</ImplicitUsings> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference> <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.10" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> </PackageReference> <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.8" /> </ItemGroup> </Project>
The text was updated successfully, but these errors were encountered:
Confirmed, minimal repro:
var context = new MyDbContext(); public class Address { public int Id { get; set; } public int PersonId { get; set; } public Metadata Metadata { get; set; } } public class Metadata { public int Age { get; set; } public string? Interest { get; set; } } public class MyDbContext : DbContext { public DbSet<Address> Addresses { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder.UseNpgsql("Host=localhost;Username=test;Password=test"); protected override void OnModelCreating(ModelBuilder builder) { builder.Entity<Address>() .Property(e => e.Metadata) .HasColumnType("jsonb"); } }
Sorry, something went wrong.
roji
No branches or pull requests
After creating a DbContext and an entity within the
Program.cs
file, callingadd-migration
produces a migration file with syntax error:The produced migration looks like this and everything is okay in it (it was generated correctly) except for line 1 where it has an empty
using
:Program.cs:
The project file:
The text was updated successfully, but these errors were encountered: