entity framework - Dynamic select columns with list in c# -
i having , movie class id, moviename, disc, reldate
list<movie> moviedata = db.movies.tolist(); return json(moviedata , jsonrequestbehavior.allowget);
this return below data
[ { id: 1, moviename: "junglebook", desc: "good movie", reledate: "/date(1460917800000)/" }, { id: 2, moviename: "fan", desc: "lets see movie-1", reledate: "/date(1460831400000)/" }, { id: 3, moviename: "jadu", desc: "must see", reledate: "/date(1460658600000)/" } ]
but want return data based on selected columns , eg when pass id, moviename give me below result(id , moviename dynamic condition)
[ { id: 1, moviename: "junglebook" } ]
based on column condition return me array list data specified columns.
you can start linq select columns in table , filter results :
var selecteddata = db.movies.where(x => x.id == 1).select(x => new {id = x.id, moviename = x.moviename}).tolist();
Comments
Post a Comment