c# - Linq Syntax - Selecting multiple columns -


this linq syntax using entity model

iqueryable<string> objemployee = null;  objemployee = res in _db.employees               (res.email == giveninfo || res.user_name == giveninfo)               select res.email; 

how can select multiple columns? want select res.id aswell. , how can receive those? iqueryable not work think. , called linq sql - right ?

as other answers have indicated, need use anonymous type.

as far syntax concerned, far prefer method chaining. method chaining equivalent be:-

var employee = _db.employees     .where(x => x.email == giveninfo || x.user_name == giveninfo)     .select(x => new { x.email, x.id }); 

afaik, declarative linq syntax converted method call chain similar when compiled.

update

if want entire object, have omit call select(), i.e.

var employee = _db.employees     .where(x => x.email == giveninfo || x.user_name == giveninfo); 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -