Transforming http request into linq query I wrote something that has probably done thousands of times:
a function that takes a parsed http query as input and return a linq query. 

Any input is appreciated.

public IList&lt;Lead&gt; GetLeads(NameValueCollection nvc)
{
    IQueryable&lt;MyContext&gt; queryBase = QueryBase();

    foreach (string key in nvc)
    {
        const string format = "dd-MM-yyyy";

        if (nvc[key] == "all")
            continue;


        //case where an array of possible values is sent
        const string regex = "\\[.*\\]";


        Expression&lt;Func&lt;MyContext, bool&gt;&gt; predicate = c =&gt; false;

        string[] values = nvc[key].Split(',');
        foreach (string value in values)
        {
            Expression&lt;Func&lt;MyContext, bool&gt;&gt; predicateTemp;
            DateTime date;
            switch (Regex.Replace(key, regex, ""))
            {
                case "nature":
                    string value1 = value;
                    predicateTemp =
                        c =&gt; c.Typologies.NatureDemande == value1;
                    break;
                case "departementCode":
                    string value2 = value;
                    predicateTemp = c =&gt; c.Geographies.DepartementCode == value2;
                    break;
                case "start":
                    String start = value;
                    date = DateTime.ParseExact(start, format, null);

                    DateTime date1 = date;
                    predicateTemp = c =&gt; c.Temps.Date &gt;= date1;
                    break;
                case "end":
                    String end = value;
                    date = DateTime.ParseExact(end, format, null);

                    DateTime date2 = date;
                    predicateTemp = c =&gt; c.Temps.Date &lt;= date2;
                    break;
                default:
                    predicateTemp =
                        c =&gt; true;
                    break;
            }
            predicate = OrElse(predicate, predicateTemp);
        }


        queryBase = queryBase.Where(predicate);
    }

    //query all leads
    IQueryable&lt;Lead&gt; query = (from x in queryBase
                              select new Lead
                                  {
                                      id = Convert.ToInt32(x.Leads.DemandeWeb_FK),
                                      lng = Convert.ToDouble(x.Leads.longitudeClient.Replace(",", ".")),
                                      lat = Convert.ToDouble(x.Leads.latitudeClient.Replace(",", ".")),
                                      temps = Convert.ToInt32(x.Leads.GeolocDureeTrajetDistrib),
                                      distance = Convert.ToInt32(x.Leads.GeolocDistanceRouteDistrib),
                                      nature = x.Typologies.NatureDemande,
                                      type = x.Distributeurs.DistribType,
                                      reseau = x.Distributeurs.ReseauDistributeur,
                                      instance = x.Demands.IdInstance,
                                      distribution = Convert.ToInt32(x.Distributeurs.DistribIdPointDeVente),
                                  });


    return query.ToList();
}
Here's a stab at making it a tad more performant while simplifying the syntax a bit:

//case where an array of possible values is sent
private const string MyRegex = "\\[.*\\]";

private static readonly Regex replacer = new Regex(MyRegex, RegexOptions.Compiled);

public IList&lt;Lead&gt; GetLeads(NameValueCollection nvc)
{
    var queryBase = QueryBase();

    foreach (var key in nvc.Cast&lt;string&gt;().Where(key =&gt; nvc[key] != "all"))
    {
        // case where an array of possible values is sent
        Expression&lt;Func&lt;MyContext, bool&gt;&gt; predicate = c =&gt; false;

        foreach (var value in nvc[key].Split(','))
        {
            const string Format = "dd-MM-yyyy";
            Expression&lt;Func&lt;MyContext, bool&gt;&gt; predicateTemp;
            var localValue = value;

            switch (replacer.Replace(key, string.Empty))
            {
                case "nature":
                    predicateTemp = c =&gt; c.Typologies.NatureDemande == localValue;
                    break;
                case "departementCode":
                    predicateTemp = c =&gt; c.Geographies.DepartementCode == localValue;
                    break;
                case "start":
                    predicateTemp = c =&gt; c.Temps.Date &gt;= DateTime.ParseExact(localValue, Format, null);
                    break;
                case "end":
                    predicateTemp = c =&gt; c.Temps.Date &lt;= DateTime.ParseExact(localValue, Format, null);
                    break;
                default:
                    predicateTemp = c =&gt; true;
                    break;
            }

            predicate = this.OrElse(predicate, predicateTemp);
        }

        queryBase = queryBase.Where(predicate);
    }

    // query all leads
    return queryBase.Select(x =&gt; new Lead
    {
        id = Convert.ToInt32(x.Leads.DemandeWeb_FK),
        lng = Convert.ToDouble(x.Leads.longitudeClient.Replace(",", ".")),
        lat = Convert.ToDouble(x.Leads.latitudeClient.Replace(",", ".")),
        temps = Convert.ToInt32(x.Leads.GeolocDureeTrajetDistrib),
        distance = Convert.ToInt32(x.Leads.GeolocDistanceRouteDistrib),
        nature = x.Typologies.NatureDemande,
        type = x.Distributeurs.DistribType,
        reseau = x.Distributeurs.ReseauDistributeur,
        instance = x.Demands.IdInstance,
        distribution = Convert.ToInt32(x.Distributeurs.DistribIdPointDeVente),
    }).ToList();
}