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
Post a Comment