错误是错误“无法将类型System.Collections.Generic.List<eToolsSystem.Entities.DTOs.CurrentOrder>
隐式转换为System.Collections.Generic.List<eToolsSystem.Entities.PurchaseOrderDetail>
”
我的控制器类中的代码:
[DataObjectMethod(DataObjectMethodType.Select, false)]
public List<PurchaseOrderDetail> PurchaseOrdersByVendors(int VendorId)
{
using (var context = new ToolsContext())
{
var data = from item in context.PurchaseOrderDetails
where item.PurchaseOrder.OrderDate == null
&& item.PurchaseOrder.VendorID == VendorId
select new CurrentOrder()
{
StockID = item.StockItem.StockItemID,
Description = item.StockItem.Description,
QOH = item.StockItem.QuantityOnHand,
ROL = item.StockItem.ReOrderLevel,
QOO = item.StockItem.QuantityOnOrder,
PoQty = item.Quantity,
Price = item.StockItem.PurchasePrice
};
return data.ToList();
}
}
我的DTO CurrentOrder的代码:
public class CurrentOrder
{
public int StockID { get; set; }
public string Description { get; set; }
public int QOH { get; set; }
public int ROL { get; set; }
public int QOO { get; set; }
public int PoQty { get; set; }
public decimal Price { get; set; }
}
答案 0 :(得分:1)
您正在构建CurrentOrder
的列表,但您的方法签名表明它已返回PurchaseOrderDetail
的列表
将您的方法更改为:
public List<CurrentOrder> PurchaseOrdersByVendors(int VendorId)
或返回PurchaseOrderDetail
列表以解决问题。我相信后者是您想要的,基于您的方法名称。
答案 1 :(得分:0)
您应该返回List<PurchaseOrderDetail>
而不是List<CurrentOrder>