現在,我試圖正確加入一個例外彈出。不能隱式地將類型'System.Collections.Generic.List <AnonymousType#1>'轉換爲'System.Collections.Generic.IEnumerable
這是我的控制器
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()
select new
{
APPLICANT = j,
Profile = a,
}).Take(1000).AsEnumerable();
applicantdata = applicantList.AsEnumerable().ToList();
if (applicantdata.Any())
{
Cache.Set("applicants", applicantdata, 30);
}
}
return applicantdata;
}
這是
applicantdata = applicantList.AsEnumerable().ToList();
無法隱式轉換類型錯誤 'System.Collections.Generic.List < AnonymousType#1 >' 到 「 System.Collections.Generic.IEnumerable <Applicant.Models.APPLICANT>'。顯式 轉換不存在(是否缺少強制轉換?)
如何定義'APPLICANT'? –
[不能隱式地將類型'List'轉換爲'IEnumerable ']的重複(http://stackoverflow.com/questions/16602765/cannot-implicitly-convert-type-listanonymoustype1- to-ienumerablemodels-ap) –
如果您使用'IEnumerable'作爲返回類型,那麼爲什麼要在LINQ中創建一個匿名類型? 您需要使用'select new Applicant {}' –
Nilesh