无法将类型"System.Linq.IQueryable< AnonymousType#1>"隐式转换为"System.Collections.Generic.IEnumerable< SubCateViewModel>" [英] Cannot implicitly convert type ‘System.Linq.IQueryable<AnonymousType#1>’ to ‘System.Collections.Generic.IEnumerable<SubCateViewModel>’

查看:57
本文介绍了无法将类型"System.Linq.IQueryable< AnonymousType#1>"隐式转换为"System.Collections.Generic.IEnumerable< SubCateViewModel>"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试联接三个表ProductPhotoProductProductProductPhoto时遇到此问题.我尝试了很多情况,但没有解决.有人可以帮助我摆脱困境吗?感谢您的回复!

I got this problem when I'm trying join three tables ProductPhoto, Product, and ProductProductPhoto. I tried many case but it didn't work out. Anyone could help me get out of this? Thanks for replying!

private IEnumerable<SubCateViewModel> GetSubProduct()
            {
                var context = new AdvenDBEntities();
                var subcate = (from a in context.ProductPhotoes
                              join b in context.ProductProductPhotoes on a.ProductPhotoID equals b.ProductPhotoID
                              join c in context.Products on b.ProductID equals c.ProductID
                              join d in context.ProductSubcategories on c.ProductSubcategoryID equals d.ProductSubcategoryID
                              select new
                              {
                                  a.ProductPhotoID,
                                  a.ThumbnailPhotoFileName,
                                  c.ProductID,
                                  c.Name,
                                  d.NameofBike,
                                  d.isSelected,
                              }).AsQueryable();
                         return subcate;
            }

推荐答案

尝试以下代码伙伴.

private IEnumerable<SubCateViewModel> GetSubProduct()
                {
                    var context = new AdvenDBEntities();
                    var subcate = (from a in context.ProductPhotoes
                                  join b in context.ProductProductPhotoes on a.ProductPhotoID equals b.ProductPhotoID
                                  join c in context.Products on b.ProductID equals c.ProductID
                                  join d in context.ProductSubcategories on c.ProductSubcategoryID equals d.ProductSubcategoryID
                                  select new SubCateViewModel
                                  {
                                     ProductPhotoID =  a.ProductPhotoID,
                                      ThumbnailPhotoFileName = a.ThumbnailPhotoFileName,
                                     ProductID = c.ProductID,
                                      Name = c.Name,
                                      NameofBike = d.NameofBike,
                                      isSelected = d.isSelected,
                                  });
                             return subcate.AsEnumerable();
                }

这篇关于无法将类型"System.Linq.IQueryable&lt; AnonymousType#1&gt;"隐式转换为"System.Collections.Generic.IEnumerable&lt; SubCateViewModel&gt;"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆