EF Core Add-Migration only includes key columns [Answered]

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.
[Table("Transl", Schema = "public")]
public class Transl
{
[Required]
public string Symbol;

[Required]
public string LanguageIso;

[Required]
public string Translation;

public Transl() {}
}
[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 });

}
}
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")));
_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
No referenced design-time services were found
4 Replies
Jayy
Jayy2y ago
They have to be properties
alkasel#159
alkasel#1592y ago
ohh thanks 😓 Ok I confirm now all properties are included 👍
Jayy
Jayy2y ago
Awesome
Accord
Accord2y ago
✅ This post has been marked as answered!