Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Using columns not defined in model with Entity Framework Core in ASP.NET Core 5

$
0
0

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:

  1. 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?


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>