如何在oData控制器中连接2个实体后返回IQueryable结果

时间:2018-04-07 07:47:37

标签: entity-framework linq odata odatacontroller

我有两个表 UU_DeliveryCharges SC_Countries ,我想在我的odata函数中将结果集作为这两个表的连接返回但是获得异常:

  

实体或复杂类型' ULYXModel.UU_DeliveryCharges'不能在LINQ to Entities查询中构造。

我是oData的新手,请帮助。

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;
}

型号:

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 个答案:

没有答案