2014-02-10 200 views
0

我寫了下面編譯的查詢:無法隱式轉換類型「System.Linq.IQueryable

public static Func < Modal.Entities, string, IQueryable <Modal.Staff> > 
     MyQuery = CompiledQuery.Compile((Modal.Entities U, string StaffNo) => U.Staff.Where(a => a.StaffNo == StaffNo)); 

,並用下面的語句來調用已編譯的查詢:

Modal.Staff abc = MyQuery(context, StaffNo); 

,但我得到了以下錯誤:

Cannot implicitly convert type 'System.Linq.IQueryable ' to 'Modal.Staff'. An explicit conversion exists (are you missing a cast?)

有人能幫助我嗎?

回答

0

您的查詢返回System.Linq.IQueryable,但您試圖將其分配給Modal.Staff。更改您的查詢以返回單個結果:

MyQuery = CompiledQuery.Compile((Modal.Entities U, string StaffNo) => 
     U.Staff.Where(a => a.StaffNo == StaffNo).FirstOrDefault()); 
相關問題