How to return IQueryable result after joining 2 entities in oData controller

290 Views Asked by At

I have two tables UU_DeliveryCharges and SC_Countries and I want to return result set as a join of these two in my odata function but getting an exception:

The entity or complex type 'ULYXModel.UU_DeliveryCharges' cannot be constructed in a LINQ to Entities query.

I am new in oData, please help.

oData Web API:

[EnableQuery] 
public IQueryable<UU_DeliveryCharges> GetUU_DeliveryCharges()
{
    //retrun db.UU_DeliveryCharges;

    var results = from deliveries in db.UU_DeliveryCharges                        
        join countries in db.SC_Countries on deliveries.CountryId equals countries.CountryId
        select new UU_DeliveryCharges
        {
            FlatRate = deliveries.FlatRate,
            MileRate = deliveries.MileRate,
            PickUpFee = deliveries.PickUpFee,
            DropOffFee = deliveries.DropOffFee,
            CountryName = countries.CountryName
        };

    return results;
}

Model:

public partial class UU_DeliveryCharges
{
    public int DeliveryChargeId { get; set; }     

    public Nullable<int> CountryId { get; set; }      

    public Nullable<decimal> MileRate { get; set; }

    public Nullable<decimal> FlatRate { get; set; }          

    public Nullable<decimal> PickUpFee { get; set; }

    public Nullable<decimal> DropOffFee { get; set; }           

    public string CountryName { get; set; }            
}  

public partial class SC_Countries
{
    public int CountryId { get; set; }

    public string CountryName { get; set; }           
}
0

There are 0 best solutions below