c# - Extract property of object from entity framework query -
i'm new ef , i'm having trouble doing simplest thing...
public class person : dto { public string id { get; set; } public string fname { get; set; } public string lname{ get; set; } }
i use either iqueryable<person>
or objectreuslt<person>
extract fname
object.
peopleentities entities = new peopleentities(); string querystr = "select value c peopleentity.person c c.id=" + personid; iqueryable<entityobject> query = entities.createquery<entityobject>(querystr);
i see createquery
can both return iqueryable
, objectresult
. i'd know whats lightest way can extract fnames
list query result.
i'm interpreting question "get first name of provided personid". assuming peopleentities
contains dbset<person> person
following:
public string getfirstnameforperon(string personid) { peopleentities entities = new peopleentities(); // new ef context return entities .person // person entities .where(w => w.id == personid) // id = personid .firstordefault(); // take first available .fname; // fname property }
Comments
Post a Comment