C
Join ServerC#
help
EF Core Add-Migration only includes key columns [Answered]
Aalkasel8/26/2022
Hi,
I'm using EF Core for the first time. When I run Add-Migrations command, the migration classes are generated, but in every table only primary keys column(s) are included.
I have a couple of classes, e.g.
And I have the following ApplicationDbContext
And in Program.cs I have
If I run Update-Database, the database is successfully updated, but only colums representing a primary key are included in the table.
Add-Migration produces no error, the only line a bit strange is
I'm using EF Core for the first time. When I run Add-Migrations command, the migration classes are generated, but in every table only primary keys column(s) are included.
I have a couple of classes, e.g.
[Table("Transl", Schema = "public")]
public class Transl
{
[Required]
public string Symbol;
[Required]
public string LanguageIso;
[Required]
public string Translation;
public Transl() {}
}
And I have the following ApplicationDbContext
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }
public DbSet<Lang> Lang { get; set; }
public DbSet<Transl> Transl { get; set; }
protected override void OnModelCreating(ModelBuilder builder) {
base.OnModelCreating(builder);
builder.Entity<Transl>().HasKey(x => new { x.Symbol, x.LanguageIso });
}
}
And in Program.cs I have
_builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(_builder.Configuration.GetConnectionString("DefaultConnection")));
If I run Update-Database, the database is successfully updated, but only colums representing a primary key are included in the table.
Add-Migration produces no error, the only line a bit strange is
No referenced design-time services were found
JJayy8/26/2022
They have to be properties
Aalkasel8/26/2022
ohh
Aalkasel8/26/2022
thanks 😓
Aalkasel8/26/2022
Ok I confirm now all properties are included 👍
JJayy8/26/2022
Awesome
AAccord8/26/2022
✅ This post has been marked as answered!