Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法将类型“System.Collections.Generic.List”隐式转换为“System.Collections.Generic.IEnumerable_C#_Asp.net_Asp.net Mvc_Linq_Entity Framework - Fatal编程技术网

C# 无法将类型“System.Collections.Generic.List”隐式转换为“System.Collections.Generic.IEnumerable

C# 无法将类型“System.Collections.Generic.List”隐式转换为“System.Collections.Generic.IEnumerable,c#,asp.net,asp.net-mvc,linq,entity-framework,C#,Asp.net,Asp.net Mvc,Linq,Entity Framework,当我添加DefaultIfEmpty语句以右键连接数据时,我的控制器出现异常 这是我的控制器: public IEnumerable<APPLICANT> GetApplicant() { IEnumerable<APPLICANT> applicantdata = Cache.Get("applicants") as IEnumerable<APPLICANT>; IEnumerable<Prof

当我添加DefaultIfEmpty语句以右键连接数据时,我的控制器出现异常

这是我的控制器:

        public IEnumerable<APPLICANT> GetApplicant()
    {
        IEnumerable<APPLICANT> applicantdata = Cache.Get("applicants") as IEnumerable<APPLICANT>;
        IEnumerable<Profile> profiledata = Cache.Get("profiles") as IEnumerable<Profile>;


        if (applicantdata == null)
        {



            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(new APPLICANT())
                                 select new
                                            {
                                               APPLICANT = j, 
                                               Profile = a,
                                            }).Take(1000).AsEnumerable();

                   applicantdata = applicantList.ToList();


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

    }
这是个例外


无法将类型“System.Collections.Generic.List”隐式转换为“System.Collections.Generic.IEnumerable”。存在显式转换。是否缺少强制转换

对我来说,这听起来像是一个编译时错误,而不是一个异常,但无论如何

查看您的select子句:

那只是一种匿名类型。您希望如何将其转换为申请人?也许你只是想要申请者的一部分?这并不十分清楚,但如果您试图将其转换为命名类型的列表,则基本上不需要匿名类型。如果您确实希望申请人在j范围变量中,只需使用:

select j

顺便说一句,最好尽量遵循.NET命名约定-类型名和属性名都不应该出现在SHOUTY_的情况下。

先生,谢谢。我只想让它像这样@恩里奎吉尔:不,你没有,因为那是使用匿名类型。您正试图为IEnumerable类型的变量赋值-因此您不能使用匿名类型。选择j后,它会闪烁一个NotSupportedException,用户代码未处理该实体或复杂类型“Model.applicator”不能在LINQ to Entities查询中构造。@EnriqueGil:可能唯一的问题是您使用DefaultIfEmpty。现在还不清楚你为什么在这种情况下使用它。@EnriqueGil:不,因为你甚至从来没有解释过你想要实现什么。老实说,看起来你正试图通过从其他地方剪切和粘贴来学习LINQ。那不是个好主意。您应该从基础开始学习if,并真正理解您的代码。
select new
{
    APPLICANT = j, 
    Profile = a,
}
select j