无法隐式转换类型'System.Collections.Generic.IEnumerable <System.Collections.Generic.ICollection

john Gu

我在asp.net mvc wen应用程序中定义了以下模型类:-

public class CustomerDetails
{
    public AccountDefinition AccountDefinition {get; set;}
    public SDOrganization SDOrganization {get; set;}
    public ICollection<SiteDefinition> SiteDefinition { get; set; }
    public ICollection<AaaPostalAddress> AaaPostalAddress { get; set; }
    public ICollection<AaaContactInfo> AaaContactInfo { get; set; }
    public virtual ICollection<UserSiteMapping> UserSiteMapping { get; set; } 
}

然后我写下面的查询:

var customerDetails = entities.AccountDefinitions
    .Where(a => a.ORG_ID == id)
    .Select(cd => new CustomerDetails
    {
        AccountDefinition = cd,
        SDOrganization = cd.SDOrganization,
        AaaPostalAddress = cd.SDOrganization.AaaPostalAddresses,
        AaaContactInfo = cd.SDOrganization.AaaContactInfoes,
        SiteDefinition = cd.SiteDefinitions,
        UserSiteMapping = cd.SiteDefinitions.Select(p2 => p2.UserSiteMappings) //this is raising the exception
    })
    .SingleOrDefault();

return customerDetails;

但我得到以下误导性错误:

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

我不知道是什么导致了错误,因为我选择了UserSiteMapping与SiteDefinition相关的内容,并且将它们分配给UserSiteMapping的集合(在我的视图模型中定义)???

马尔辛·尤拉塞克(MarcinJuraszek)

使用SelectMany来代替:

UserSiteMapping = cd.SiteDefinitions.SelectMany(p2 => p2.UserSiteMappings)

您可能还需要ToList()ToArray()致电以从切换IEnumerable<T>ICollection<T>

UserSiteMapping = cd.SiteDefinitions.SelectMany(p2 => p2.UserSiteMappings).ToList()

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

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

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

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

来自分类Dev

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

来自分类Dev

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

来自分类Dev

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

来自分类Dev

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

来自分类Dev

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

来自分类Dev

无法将类型'System.Collections.Generic.IEnumerable <string>隐式转换为字符串

来自分类Dev

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

来自分类Dev

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

来自分类Dev

无法将类型'string'隐式转换为'System.Collections.Generic.ICollection <WebApplication2.Entry>'

来自分类Dev

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

来自分类Dev

无法将类型'System.Collections.Generic.IEnumerable'隐式转换为'System.Web.Mvc.ActionResult'

来自分类Dev

无法将类型System.Collections.Generic.Ienumerable <string>隐式转换为system.Linq.IOrderedEnumerable <AnonymousType#1>

来自分类Dev

无法将类型'System.Collections.Generic.IEnumerable'隐式转换为'System.Web.Mvc.ActionResult'

来自分类Dev

无法将类型'System.Collections.Generic.List <String>'隐式转换为'System.Collections.Generic.IEnumerable <turon.Model.Products_Products>

来自分类Dev

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

来自分类Dev

无法将类型'Newtonsoft.Json.Linq.JObject'隐式转换为'System.Collections.Generic.IEnumerable <Employee>'

来自分类Dev

CS0266无法将类型'System.Collections.Generic.IEnumerable <char>'隐式转换为'string'

来自分类Dev

无法将类型'Newtonsoft.Json.Linq.JObject'隐式转换为'System.Collections.Generic.IEnumerable <Employee>'

来自分类Dev

“无法将类型'System.Collections.Generic.IEnumerable <C3S.Models.Permission>'隐式转换为'bool'。”

来自分类Dev

C#:错误-无法将类型'int'隐式转换为'System.Collections.Generic.IEnumerable <double>'

来自分类Dev

无法从System.Collections.Generic.List转换为System.Collections.Generic.IEnumerable

来自分类Dev

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

来自分类Dev

无法将类型'System.Web.Mvc.SelectList'隐式转换为'System.Collections.Generic.ICollection <System.Web.Mvc.SelectList>'

来自分类Dev

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

来自分类Dev

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

来自分类Dev

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

来自分类Dev

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

来自分类Dev

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

Related 相关文章

  1. 1

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

  2. 2

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

  3. 3

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

  4. 4

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

  5. 5

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

  6. 6

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

  7. 7

    无法将类型'System.Collections.Generic.IEnumerable <string>隐式转换为字符串

  8. 8

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

  9. 9

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

  10. 10

    无法将类型'string'隐式转换为'System.Collections.Generic.ICollection <WebApplication2.Entry>'

  11. 11

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

  12. 12

    无法将类型'System.Collections.Generic.IEnumerable'隐式转换为'System.Web.Mvc.ActionResult'

  13. 13

    无法将类型System.Collections.Generic.Ienumerable <string>隐式转换为system.Linq.IOrderedEnumerable <AnonymousType#1>

  14. 14

    无法将类型'System.Collections.Generic.IEnumerable'隐式转换为'System.Web.Mvc.ActionResult'

  15. 15

    无法将类型'System.Collections.Generic.List <String>'隐式转换为'System.Collections.Generic.IEnumerable <turon.Model.Products_Products>

  16. 16

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

  17. 17

    无法将类型'Newtonsoft.Json.Linq.JObject'隐式转换为'System.Collections.Generic.IEnumerable <Employee>'

  18. 18

    CS0266无法将类型'System.Collections.Generic.IEnumerable <char>'隐式转换为'string'

  19. 19

    无法将类型'Newtonsoft.Json.Linq.JObject'隐式转换为'System.Collections.Generic.IEnumerable <Employee>'

  20. 20

    “无法将类型'System.Collections.Generic.IEnumerable <C3S.Models.Permission>'隐式转换为'bool'。”

  21. 21

    C#:错误-无法将类型'int'隐式转换为'System.Collections.Generic.IEnumerable <double>'

  22. 22

    无法从System.Collections.Generic.List转换为System.Collections.Generic.IEnumerable

  23. 23

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

  24. 24

    无法将类型'System.Web.Mvc.SelectList'隐式转换为'System.Collections.Generic.ICollection <System.Web.Mvc.SelectList>'

  25. 25

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

  26. 26

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

  27. 27

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

  28. 28

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

  29. 29

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

热门标签

归档