'Programmatically add columns to a DBSet in Entity Framework 6, EF Core for .NET 6

In our app we use .net Framework 4.8, and soon will move to .net6

We are moving to a multi tenant architecture where each tenant will have their own database, most tables being identical between tenants. However some tables will be modified in the field by the tenant adding user defined columns.

I have studied EF OnModelCreating, and I see ways to re map between fields, rename field, etc. What I cant find is a way to programmatically add columns to an existing DBSet

Since we will soon move to .net6 please consider how to do so in that environment.

Example - db.SimpleTable has columns Id, Name

Column ProductNumber is added at runtime by the tenant.

Now the class defined within EF for SimpleTable has Id, Name, but how does one programmatically add ProductNumber at the point of creating the dbContext such that changes to it are mapped, fetched, and updated, without creating a new SimpleTable class and linking it in?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source