c# - Lambda expressions from sql -


i trying in lambda :

select hint [tablename] answer = 'answer';

this have tried far :

    public modelsql.puzzlecontent getacrossclue(string answer)     {          return context.puzzlecontents.where(c => c.answer.equals(answer)).select( g => new {g.hint});     } 

error says :

cannot implicitly convert type 'system.linq.iqueryable' 'istellar.modelsql.puzzlecontent'. explicit conversion exists (are missing cast?)

your problem select returns colection , method returns single instance.

assuming g.hint modelsql.puzzlecontent instance, should add firstordefault @ end retrieve single item.

something missed you're trying return anonymous type trough new { g.hint } , that's not valid. need return concrete type.

again, assuming g.hint modelsql.puzzlecontent instance, should have

return context.puzzlecontents     .where(c => c.answer.equals(answer))     .select(g => g.hint)     .firstordefault(); 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -