简体   繁体   English

Cannot convert type 'System.Collections.Generic.List< >' to 'System.Collections.Generic.IList< >' c# MongoDB

[英]Cannot convert type 'System.Collections.Generic.List< >' to 'System.Collections.Generic.IList< >' c# MongoDB

var testa = await _cartCollection.Find(x => x.id_cart == entity.id_cart).ToListAsync();
List<ListCartRRModel> cart = testa.ToList();

i want to pass the array value from testa into the ListCartRRModel but i dont know how我想将数组值从 testa 传递到 ListCartRRModel 但我不知道如何

can you guys show me the right way?你们能告诉我正确的方法吗?

try to use "Select" in Linq:尝试在 Linq 中使用“选择”:

List<ListCartRRModel> carts = await _cartCollection
   .Find(x => x.id_cart == entity.id_cart)
   .Select(t=>new ListCartRRModel{ t.id_cart, ...})
   .ToListAsync<ListCartRRModel>();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法隐式转换类型System.Collections.Generic.IList System.Collections.Generic.List - Cannot implicitly convert type System.Collections.Generic.IList System.Collections.Generic.List 无法将类型&#39;System.Collections.Generic.List &lt;&gt;&#39;隐式转换为&#39;System.Collections.Generic.IList &lt;&gt;&#39; - Cannot implicitly convert type 'System.Collections.Generic.List< >' to 'System.Collections.Generic.IList< >' 无法隐式转换类型&#39;System.Collections.Generic.List <AnonymousType#1> &#39;到&#39;System.Collections.Generic.IList - Cannot implicitly convert type 'System.Collections.Generic.List<AnonymousType#1>' to 'System.Collections.Generic.IList 无法隐式转换类型'System.Collections.Generic.List<string> ' 到 'System.Collections.Generic.IList <lm_webapi.controllers.items></lm_webapi.controllers.items></string> - Cannot implicity convert type 'System.Collections.Generic.List<string>' to 'System.Collections.Generic.IList<LM_WebApi.Controllers.Items> 无法将类型“字符串”转换为“System.Collections.Generic.IList”<string></string> - Cannot convert type 'string' to 'System.Collections.Generic.IList<string> 无法将 System.Collections.Generic.List[System.Object] 类型的对象转换为 System.Collections.Generic.IList[ShortCodeList] - Unable to cast object of type System.Collections.Generic.List[System.Object] to type System.Collections.Generic.IList[ShortCodeList] 无法将类型'System.Collections.IList'隐式转换为'System.Collections.Generic.List - Cannot implicitly convert type 'System.Collections.IList' to 'System.Collections.Generic.List C#:无法隐式转换类型“System.Collections.Generic.List”<char> &#39; 到 &#39;System.Collections.Generic.List<string> &#39; - C#: Cannot implicitly convert type 'System.Collections.Generic.List<char>' to 'System.Collections.Generic.List<string>' C# SelectMany 错误“无法隐式转换类型‘System.Collections.Generic.List<char> ' 到 'System.Collections.Generic.List<list> ’”</list></char> - C# SelectMany error " Cannot Implicitly convert type 'System.Collections.Generic.List<char>' to 'System.Collections.Generic.List<List>' " 无法隐式转换类型&#39;System.Collections.Generic.list <fooClass> &#39;到&#39;System.Collections.Generic.List <T> - Cannot Implicitly convert type 'System.Collections.Generic.list<fooClass>' to 'System.Collections.Generic.List<T>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM