How to write dynamic SQL Queries in Entity Framework? -


i have page user can input sql query. query can against table in database. need execute query against corresponding table , show result in view. how this?

for eg: user can input select * abc or select max(price) items.

i tried:

var results = dbcontext.database.sqlquery<string>(query).tolist(); 

but throws error:

the data reader has more 1 field. multiple fields not valid edm primitive or enumeration types.

whatever result should able pass view , display it.

please help.

you can use

 sqlquery<dynamic>"  

this resolve error able count of result returned. can verify query has returned data. still need know type of returned data.

it risk of providing user input query database.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -