forum

Home / DeveloperSection / Forums / How to get all optional parameters from SQL Server

How to get all optional parameters from SQL Server

Anonymous User220804-Nov-2014

I am creating a Web API GET (all) method with multiple optional parameters. I'm trying this with 1 parameter first but eventually, I want 5 optional parameters. Starting with 1 parameter I have 2 situations: parameter is filled in and parameter is not filled in.

Parameter is filled in

from r in db.requests where r.status == status selectnewModels.Request

Parameter is not filled in

from r in db.requests selectnewModels.Request

I can not get both situations to work together so my question is: How can I combine these 2 situations?

Controller

publicIEnumerable<Request>Get(string status =""){var requests =from r in db.requests //where r.status == statusselectnewModels.Request{ ID = r.ID,...more properties };return(IEnumerable<Request>)requests;}

Route

protectedvoidApplication_Start(){RouteTable.Routes.MapHttpRoute( name:"API Default", routeTemplate:"api/{controller}/{id}", defaults:new{ id =RouteParameter.Optional});}

Updated on 04-Nov-2014
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By