forum

home / developersection / forums / how to get all optional parameters from sql server

How to get all optional parameters from SQL Server

Anonymous User 2415 04-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
select new Models.Request

Parameter is not filled in

from r in db.requests
select new Models.Request

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

Controller

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

Route

protected void Application_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