ASP .NET Core MVC 5 application runs in different Postgres databases.
Table names are same in all databases. Base column names and types are same in all databases.
Tables can also contain additional columns added to database after application creation using
ALTER table mytable ADD COLUMN mycol TYPE mytype
commands.
Custom column names and types are different in different databases. Custom column list is also stored in table Datadictionary which contains
table name, custom column name and custom column type.
Those columns should displayed to user in view. Views shoud dynamically detect added columns show and allow to change their content.How to get data from those columns and allow users to change them ?
I'm thinking about 2 possibilities:
- Create derived from Varcoltable class which has additional columns, compilethis class at runtime and pass in to DbContext. Tried
var ctx = new MyDbContext();
dynamic list = ctx.Varcoltables.FromSqlRaw("select * from varcoltable");2. Add property like Dictionary<string,object> CustomColumns; into base entity class and fill it with custom column values.
public class Varcoltables : EntityBase { } public class EntityBase { public Dictionary<string,object> CustomColumns; } Tried to use dynamic as child class :
class Varcoltable : dynamic { }but got compile error 'Cannot derive from dynamic type'
How to implement this ?Are there some framework source code, documentation or samples how to implement this?