0

I am looking for generic solution for below implementation.

We have stored some of the database table names in one table and this table list we have populated in the dropdownlist and based on the selected table name we want to show the data with there columns in grid and the grid will have CRUD operation buttons.

For these tables we already have the models generated in the project.

But here we want to use generic view model/solution as columns(name,datatype etc) will get vary as per the table selected, so we cannot create a model which will have defined set of properties.

And to retrieve the selected table data we have written the stored procedure. But to retrieve the data returned from the stored procedure we need to provide the model name. Below is sample code

List<SomeModel> modelList = new List<SomeModel>();

modelList = dbcontext.Set<SomeModel>().FromSql("some sp name @tableName={0}", TableName).ToList();

return modelList;

So how can we create generic view model which will accept any table/model data and also, how can set that view model in dbcontext.Set<SomeModel> while executing the stored procedure ?

XamDev
  • 3,377
  • 12
  • 58
  • 97

1 Answers1

1

You asked for

a generic view-model which will accept any table/model data.

You are talking about the DataTable class which is what people used before things got strongly-typed. Populating it has already been answered here.

Community
  • 1
  • 1
  • Yeah. . this kind of solution I was looking. . how should I define the 'some model'.. a blank model ? – XamDev Mar 17 '17 at 16:19