c# - 方法 'System.Linq.Queryable.SelectMany System.Linq.IQueryable 的类型参数

标签 c# asp.net asp.net-mvc linq entity-framework

在编辑我的 Repository 类时弹出一个错误

 var applicantList = (from a in context.Profiles
                             join app in context.APPLICANTs
                                on a.PROFILE_ID equals app.Profile_id into joined
                              from j in joined.DefaultIfEmpty()//.OrderBy(v => v.APPLICANT_ID)
                             select j //<--  this is APPLICANTs type
                               ).Take(1000);

   applicantdata = applicantList
                  .SelectMany(c => c.APPLICANTs) //this line added
                  .AsQueryable().OrderBy(v => v.APPLICANT_ID).ToList();

                if (applicantdata.Any())
                {
                    Cache.Set("applicants", applicantdata, 30);
                }
            }
            return applicantdata;

我在

遇到异常
.SelectMany(c => c.APPLICANTs) //this line added

说:

The type arguments for method 'System.Linq.Queryable.SelectMany(System.Linq.IQueryable, System.Linq.Expressions.Expression>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly

最佳答案

SelectMany 接受一个对象集合,其中每个对象都有一个集合属性。

您在第一条语句中选择了 APPLICANTs 集合并在其上运行 SelectMany 似乎没有意义。

查看这些链接以更好地了解 SelectMany。

http://msdn.microsoft.com/en-us/library/bb534336.aspx
Difference Between Select and SelectMany

关于c# - 方法 'System.Linq.Queryable.SelectMany System.Linq.IQueryable 的类型参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16644135/

相关文章:

c# - 结合 XmlSerializer 和 XmlWriter?

c# - 使用 foreach 迭代时如何知道行索引?

c# - 是否可以以编程方式隐藏单选按钮列表的特定列表项?

c# - 放置多个显示错误 :There is already an open DataReader associated with this Command which must be closed first 的 sql 命令时

asp.net-mvc - ASP.NET MVC Telerik 网格 : How to make one column read only on edit?

c#内存性能和加速

c# - 微软办公助手

javascript - 指定单击链接时要加载的 xml 文件

c# - PSEXEC 通过命令提示符运行成功,但在 ASP .Net/C# 中失败

c# - 在 ASP.NET MVC Action 中使用 HttpClient 调用 SSRS