asp.net mvc - Get dynamic table name in MVC with Entity Framework -
i know there lot of solutions such query i'm not able implement of them.
i'm passing table name function , want ef table result respective table value passed.
so function (a jsonresult
) in controller:-
public jsonresult fetchtbldata() { string mytablename= request.form["tblname"].tostring(); using (ebcontext db = new ebcontext()) { try { var edutbllist = db.(**mytablename**).tolist(); // want implement here. } catch (exception ex) { string innermessage = (ex.innerexception != null) ? ex.innerexception.message : ""; } return new jsonresult { data = edutbllist, jsonrequestbehavior = jsonrequestbehavior.allowget }; } }
how can without code modification , simplest approach using ef or linq? please help
try below code:
public jsonresult fetchtbldata() { string mytablename= request.form["tblname"].tostring(); using (ebcontext db = new ebcontext()) { try { type tabletype; switch(mytablename) { case "mytablename": tabletype= typeof(tableentityname); break; } var dbquery = context.set(tabletype); var edutbllist = result.tolist(); // want implement here. } catch (exception ex) { string innermessage = (ex.innerexception != null) ? ex.innerexception.message : ""; } return new jsonresult { data = edutbllist, jsonrequestbehavior = jsonrequestbehavior.allowget }; } }
Comments
Post a Comment