【发布时间】:2014-10-22 06:14:18
【问题描述】:
这篇文章有很多可能的重复项。但我尝试了其中的大多数,不幸的是我的错误仍然存在 发生。
错误是:错误 1 无法将类型
'System.Collections.Generic.List<Report.Business.ViewModels.InvoiceMaster>'隐式转换为'System.Collections.Generic.IList<ICSNew.Data.InvoiceHD>'。存在显式转换(您是否缺少演员表?)
public IList<InvoiceHD> GetAllInvoiceMasterDetailsByInvoiceId(int InvoiceId)
{
var dbMstDtl = ireportrepository.GetAllInvoiceMasterDetailsByInvoiceId(InvoiceId);
var MstDtl = from mst in dbMstDtl
select new Report.Business.ViewModels.InvoiceMaster
{
ModifiedDate = mst.ModifiedDate,
SubTotal = Convert.ToDecimal(mst.SubTotal),
TotalDiscount = Convert.ToDecimal(mst.TotalDiscount),
VAT = Convert.ToDecimal(mst.VAT),
NBT = Convert.ToDecimal(mst.NBT),
AmtAfterDiscount = Convert.ToDecimal(mst.AmtAfterDiscount)
};
return MstDtl.ToList();
}
在一些帖子中,我看到他们使用 return MstDtl.AsEnumerable().ToList();
解决了这个问题但在我的情况下它也不起作用(出现错误)
【问题讨论】:
-
你试过
return MstDtl as IList<InvoiceHD> -
您正在创建
InvoiceMaster的集合,因此您的签名需要为public IList<InvoiceMaster> ... -
InvoiceMaster 和 InvoiceHD 有什么关系?
-
@vallabha:每次都只会返回
null,因为像这样的LINQ查询的结果从不IList<T>,不管T. -
@JonSkeet 感谢更新我