asp.net - Restricting values from LINQ in a WebMethod JSON Response -
i need restrict values homecoming page in web method without using sort of proxy object.
let's have auto class next class
public class auto { public int id { get; set; } public string name { get; set; } public string engine { get; set; } }
and webmethod looks like;
[webmethod] public static list<car> searchcars(string search) { var cars = car.all().where(x => x.name.startswith(search)); homecoming cars.tolist(); }
the list get's homecoming page has attributes. how can exclude .. engine attribute id , name return?
the above purely fictional example, in real world i'm using subsonic3 objects homecoming list etc.
you can utilize projection select fields want returned. this:
[webmethod] public static list<car> searchcars(string search) { var cars = car.all().where(x => x.name.startswith(search)).select(x => new { x.id, x.name }); homecoming cars.tolist(); }
asp.net web-services
No comments:
Post a Comment