2013-05-09 44 views
0

這是我第一次遇到這個錯誤。 有人可以幫助我嗎?NotSupportedException實體或複合類型不能在LINQ to Entity查詢中構造ASP.Net MVC 3

 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 list = (from f in context.APPLICANTs 
         select f.APPLICANT_ID).ToList(); 
      var applicantList = (from a in context.Profiles 
           join app in context.APPLICANTs on a.PROFILE_ID equals app.Profile_id 
           where list.Contains(app.APPLICANT_ID) 
           select new APPLICANT()); 

      applicantdata = applicantList.Where(v => v.APPLICANT_LastName != null && v.APPLICANT_LastName != "").OrderBy(v => v.APPLICANT_ID).ToList(); 

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

和IM有錯誤在這行

applicantdata = applicantList.Where(v => v.APPLICANT_LastName != null && v.APPLICANT_LastName != "").OrderBy(v => v.APPLICANT_ID).ToList(); 

感謝,如果有人可以幫助

+0

這是奇怪的,代碼似乎是正確,是你一定要複製/粘貼的正確的代碼導致這個問題?你爲什麼要測試'APPLICANT_LastName!= null'兩次?也許你發佈了錯誤的代碼? – 2013-05-09 03:49:16

+0

我發佈的是我得到錯誤的地方。 。 。我只聲明APPLICANT_LastName!= null一次 – 2013-05-09 03:54:28

回答

0

變化

var applicantList = (from a in context.Profiles 
    join app in context.APPLICANTs on a.PROFILE_ID equals app.Profile_id 
    where list.Contains(app.APPLICANT_ID) 
    select new APPLICANT()); 

var applicantList = (from a in context.Profiles 
     join app in context.APPLICANTs on a.PROFILE_ID equals app.Profile_id 
     where list.Contains(app.APPLICANT_ID) 
     select app); 

,如果你沒有任何數據創建new APPLICANT()你新創建的申請人

applicantList.Where(v => v.APPLICANT_LastName != null && v.APPLICANT_LastName != "")

可以換到

applicantList.Where(v => !String.IsNullOrEmpty(v.APPLICANT_LastName)) 
相關問題