user3291627
user3291627

Reputation: 5

Cannot implicitly convert type 'System.Linq.IQueryable

I wrote the following compiled query:

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

and used the following statement to invoke the compiled query:

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

But I got the following error:

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

Can somebody help me?

Upvotes: 0

Views: 1292

Answers (1)

alexmac
alexmac

Reputation: 19567

Your query returns System.Linq.IQueryable, but you are trying to assign it to Modal.Staff. Change your query to return single result:

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

Upvotes: 1

Related Questions