无法将类型'System.Collections.Generic.List <>'隐式转换为'System.Collections.Generic.IList <>'

技术专家

这篇文章可能有很多重复项。但是我尝试了其中的大多数,不幸的是我的错误仍然发生。

错误为:错误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();时,此问题已解决

但在我的情况下,它也无法正常工作(出现错误)

乔恩·斯基特

假设InvoiceMaster派生自或实现InvoiceHD,并且您使用的是C#4和.NET 4或更高版本,则可以使用通用方差:

return MstDtl.ToList<InvoiceHD>();

它使用的事实,一个IEnumerable<InvoiceMaster>IEnumerable<InvoiceHD>因为IEnumerable<T>协变T

解决该问题的另一种方法是更改MstDtl使用显式类型的声明

IEnumerable<InvoiceMaster> MstDtl = ...;

(我还建议遵循常规的C#命名,其中局部变量以小写字母开头,但这是另一回事。)

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

无法将类型'System.Collections.IList'隐式转换为'System.Collections.Generic.List

来自分类Dev

无法将类型'System.Collections.Generic.List <>'隐式转换为'System.Collections.Generic.IList <>'

来自分类Dev

无法将类型'System.Collections.Generic.List <string>'隐式转换为'System.Collections.Generic.IList <LM_WebApi.Controllers.Items>

来自分类Dev

将类型'System.Collections.Generic.List <string>'转换为'System.Collections.Generic.IList <>'

来自分类Dev

无法将类型“System.Collections.Generic.List<<匿名类型:>>”隐式转换为“System.Collections.Generic.List”

来自分类Dev

无法将类型'System.Collections.Generic.List <AnonymousType#1>'隐式转换为'System.Collections.Generic.List

来自分类Dev

无法将类型System.Collections.Generic.List <>隐式转换为System.Collections.Generic.List <>

来自分类Dev

无法将类型“System.Collections.Generic.List”隐式转换为“System.Collections.Generic.List<Model.Room”

来自分类Dev

无法将类型'System.Collections.Generic.List <>'转换为'System.Collections.Generic.IList <>'c#MongoDB

来自分类Dev

错误“无法将类型“System.Collections.Generic.IEnumerable<int>”隐式转换为“System.Collections.Generic.List<int>”

来自分类Dev

无法将类型'System.Linq.IQueryable'隐式转换为'System.Collections.Generic.List'

来自分类Dev

无法将类型'System.Linq.IQueryable'隐式转换为'System.Collections.Generic.List

来自分类Dev

无法将类型'System.Collections.Generic.List <>'隐式转换为'IList <>'。存在显式转换(您是否缺少演员表?)

来自分类Dev

无法将类型隐式转换为'System.Collections.Generic.List

来自分类Dev

无法将类型'void'隐式转换为'System.Collections.Generic.List <string>'

来自分类Dev

无法将类型System.Collections.Generic.List <IEnumerable>隐式转换为<IEnumerable

来自分类Dev

无法将类型'int'隐式转换为'System.Collections.Generic.List <QuickTest.Stock>'

来自分类Dev

无法将类型“ void”隐式转换为“ System.Collections.Generic.List”以用于返回语句

来自分类Dev

无法将类型'System.Collections.Generic.List'隐式转换为'string'

来自分类Dev

无法将匿名类型隐式转换为 System.Collections.Generic.List

来自分类Dev

无法将类型“System.Collections.Generic.List<Object>”隐式转换为“string”

来自分类Dev

无法将类型“字符串”隐式转换为“System.Collections.Generic.List<int>”

来自分类Dev

无法隐式转换类型'System.Collections.Generic.List

来自分类Dev

无法将类型'System.Collections.Generic.List <System.Data.DataRow>'隐式转换为'System.Collections.Generic.List <string>'

来自分类Dev

无法将类型'System.Collections.Generic.List <>'隐式转换为'System.Threading.Tasks.Task <>>

来自分类Dev

无法将类型'System.Collections.Generic.List <MODEL#1>'隐式转换为'System.Collections.Generic.List <Model#2>

来自分类Dev

无法将类型'System.Collections.Generic.List <AnonymousType#1>'隐式转换为'System.Collections.Generic.List <string>'

来自分类Dev

无法将类型'System.Collections.Generic.List <AnonymousType#1>'隐式转换为'System.Collections.Generic.List <FirstApp.Model.TeamDetails>

来自分类Dev

无法将类型'System.Collections.Generic.IEnumerable隐式转换为System.Collections.Generic.IEnumerable <TiendaDeportes.producto>

Related 相关文章

  1. 1

    无法将类型'System.Collections.IList'隐式转换为'System.Collections.Generic.List

  2. 2

    无法将类型'System.Collections.Generic.List <>'隐式转换为'System.Collections.Generic.IList <>'

  3. 3

    无法将类型'System.Collections.Generic.List <string>'隐式转换为'System.Collections.Generic.IList <LM_WebApi.Controllers.Items>

  4. 4

    将类型'System.Collections.Generic.List <string>'转换为'System.Collections.Generic.IList <>'

  5. 5

    无法将类型“System.Collections.Generic.List<<匿名类型:>>”隐式转换为“System.Collections.Generic.List”

  6. 6

    无法将类型'System.Collections.Generic.List <AnonymousType#1>'隐式转换为'System.Collections.Generic.List

  7. 7

    无法将类型System.Collections.Generic.List <>隐式转换为System.Collections.Generic.List <>

  8. 8

    无法将类型“System.Collections.Generic.List”隐式转换为“System.Collections.Generic.List<Model.Room”

  9. 9

    无法将类型'System.Collections.Generic.List <>'转换为'System.Collections.Generic.IList <>'c#MongoDB

  10. 10

    错误“无法将类型“System.Collections.Generic.IEnumerable<int>”隐式转换为“System.Collections.Generic.List<int>”

  11. 11

    无法将类型'System.Linq.IQueryable'隐式转换为'System.Collections.Generic.List'

  12. 12

    无法将类型'System.Linq.IQueryable'隐式转换为'System.Collections.Generic.List

  13. 13

    无法将类型'System.Collections.Generic.List <>'隐式转换为'IList <>'。存在显式转换(您是否缺少演员表?)

  14. 14

    无法将类型隐式转换为'System.Collections.Generic.List

  15. 15

    无法将类型'void'隐式转换为'System.Collections.Generic.List <string>'

  16. 16

    无法将类型System.Collections.Generic.List <IEnumerable>隐式转换为<IEnumerable

  17. 17

    无法将类型'int'隐式转换为'System.Collections.Generic.List <QuickTest.Stock>'

  18. 18

    无法将类型“ void”隐式转换为“ System.Collections.Generic.List”以用于返回语句

  19. 19

    无法将类型'System.Collections.Generic.List'隐式转换为'string'

  20. 20

    无法将匿名类型隐式转换为 System.Collections.Generic.List

  21. 21

    无法将类型“System.Collections.Generic.List<Object>”隐式转换为“string”

  22. 22

    无法将类型“字符串”隐式转换为“System.Collections.Generic.List<int>”

  23. 23

    无法隐式转换类型'System.Collections.Generic.List

  24. 24

    无法将类型'System.Collections.Generic.List <System.Data.DataRow>'隐式转换为'System.Collections.Generic.List <string>'

  25. 25

    无法将类型'System.Collections.Generic.List <>'隐式转换为'System.Threading.Tasks.Task <>>

  26. 26

    无法将类型'System.Collections.Generic.List <MODEL#1>'隐式转换为'System.Collections.Generic.List <Model#2>

  27. 27

    无法将类型'System.Collections.Generic.List <AnonymousType#1>'隐式转换为'System.Collections.Generic.List <string>'

  28. 28

    无法将类型'System.Collections.Generic.List <AnonymousType#1>'隐式转换为'System.Collections.Generic.List <FirstApp.Model.TeamDetails>

  29. 29

    无法将类型'System.Collections.Generic.IEnumerable隐式转换为System.Collections.Generic.IEnumerable <TiendaDeportes.producto>

热门标签

归档