title: How to perform a LINQ join on IQueryable<T> in odata controller
body: <p>I have a WebAPI method which uses the OData Query Options to return data to the client. The entity has cityid and I want cityname from another entity using joins.</p>
  
  <p>I have tried using below Api method, which is incomplete.</p>
  
  <p><strong>Entity1:-</strong></p>
  
  <pre><code> public partial class UU_DeliveryCharges
      {
          public int DeliveryChargeId { get; set; }
          public Nullable&lt;int&gt; CityId { get; set; }
          public Nullable&lt;int&gt; VehicleTypeId { get; set; }
          public Nullable&lt;decimal&gt; MileRate { get; set; }
          public Nullable&lt;decimal&gt; FlatRate { get; set; }
          public Nullable&lt;decimal&gt; FlatMile { get; set; }
          public Nullable&lt;decimal&gt; PickUpFee { get; set; }
          public Nullable&lt;decimal&gt; DropOffFee { get; set; }
          public Nullable&lt;int&gt; CreateBy { get; set; }
          public Nullable&lt;System.DateTime&gt; SysDate { get; set; }
          public Nullable&lt;bool&gt; Status { get; set; }
      }
  </code></pre>
  
  <p><strong>Entity2:-</strong></p>
  
  <pre><code> public partial class SC_Cities
      {
          public int CityId { get; set; }
          public Nullable&lt;int&gt; StateId { get; set; }
          public string CityName { get; set; }
          public Nullable&lt;bool&gt; CityStatus { get; set; }
      }
  </code></pre>
  
  <p><strong>WebApi Method:-</strong></p>
  
  <pre><code>    public IQueryable&lt;UU_DeliveryCharges&gt; GetUU_DeliveryCharges()
              {
                  //var aaa= db.UU_DeliveryCharges;
                  //return aaa;
  
                  var results = (from deliveries in db.UU_DeliveryCharges
                                       join vehicles in db.UU_VehicleTypes on deliveries.VehicleTypeId equals vehicles.VehicleTypeId
                                       join cities in db.SC_Cities on deliveries.CityId equals cities.CityId
                                       join states in db.SC_States on cities.StateId equals states.StateId
                                       join countries in db.SC_Countries on states.CountryId equals countries.CountryId
                                       where (deliveries.Status == true)
                                       select new { deliveries = deliveries.FlatMile, deliveries.MileRate, deliveries.PickUpFee, deliveries.DropOffFee,
                                         vehicles=vehicles.VehicleType, cities = cities.CityName, states = states.StateName, countries = countries.CountryName
                                       }).ToList();
             return results;
           }
  </code></pre>
  
  <p>Also tried by creating a new class as given below but not getting the right way, TIA.</p>
  
  <pre><code> public partial class DeliveryCharges
      {
          public string ReturnCode { get; set; } //-1:Error/0:missing or validation /1:success
          public string ReturnMessage { get; set; }
          public string CountryName { get; set; }
          public string StateName { get; set; }
          public string CityName { get; set; }
          public string VehicleName { get; set; }
          public Nullable&lt;decimal&gt; MileRate { get; set; }
          public Nullable&lt;decimal&gt; FlatRate { get; set; }
          public Nullable&lt;decimal&gt; FlatMile { get; set; }
          public Nullable&lt;decimal&gt; PickUpFee { get; set; }
          public Nullable&lt;decimal&gt; DropOffFee { get; set; }
      }
  </code></pre>
  
  <p><strong>Edit:-</strong></p>
  
  <p>I have replaced Api method by below method, which in turn evaluate the joins but not returning as a result.</p>
  
  <pre><code>public IQueryable&lt;DeliveryCharges&gt; GetUU_DeliveryCharges()
          {
              //var aaa= db.UU_DeliveryCharges;
              //return aaa;
              var results = from deliveries in db.UU_DeliveryCharges
                            join vehicles in db.UU_VehicleTypes on deliveries.VehicleTypeId equals vehicles.VehicleTypeId
                            join cities in db.SC_Cities on deliveries.CityId equals cities.CityId
                            join states in db.SC_States on cities.StateId equals states.StateId
                            join countries in db.SC_Countries on states.CountryId equals countries.CountryId
                            where (deliveries.Status == true)
                            select new DeliveryCharges
                            {
                                FlatRate = deliveries.FlatRate,
                                MileRate = deliveries.MileRate,
                                PickUpFee = deliveries.PickUpFee,
                                DropOffFee = deliveries.DropOffFee,
                                CityName = cities.CityName
                                //UU_DeliveryCharges = deliveries.FlatMile, deliveries.MileRate, deliveries.PickUpFee, deliveries.DropOffFee
                                //,vehicles = vehicles.VehicleType, cities = cities.CityName, states = states.StateName, countries = countries.CountryName
                            };
  return results;
  }
  </code></pre>
  
  <p><strong>WebApiConfig :-</strong></p>
  
  <pre><code>   public static void Register(HttpConfiguration config)
          {
       ODataConventionModelBuilder builder = new ODataConventionModelBuilder();
              builder.EntitySet&lt;UU_DeliveryCharges&gt;("UU_DeliveryCharges");
              config.Routes.MapODataRoute("odata", "odata", builder.GetEdmModel());
  }
  </code></pre>