我有两个表UU_DeliveryCharges和SC_Countries,我想在我的 odata 函数中将结果集作为这两个表的连接返回,但出现异常:
无法在 LINQ to Entities 查询中构造实体或复杂类型“ULYXModel.UU_DeliveryCharges”。
我是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; }
}