c# - Populate ViewModel with data returned from Entity Framework query -
i'm new entity framework please bare me.
i have next view model
public class vmperson { public person person { get; set; } public personaddress personaddress { get; set; } public personemploymenthistory personemploymenthistory { get; set; } }
i create phone call function , pass in personid
, seek populate person
class follows , pass viewmodel
(there other queries in here populate address , employment history)
public vmperson loadpersonbyid(int personid) { var vmperson = new vmperson(); using (var context = new context()) { var r = (from p in context.person bring together in context.personaddress on p.personid equals a.personid bring together e in context.personemployment on p.personid equals e.personid p.personid == personid select new { vmperson.person.personfirstname = p.personfirstname, vmperson.person.personsurname = p.personsurname, vmperson.person.personemail= p.personemail, vmperson.person.age = p.age }); } homecoming vmperson; }
but error on statements within select new{} is
anonymous type projection initializer, should simple name or fellow member access expression
again i'm new entity framework help highly appreciated.
thanks
public vmperson loadpersonbyid(int personid) { using (var context = new context()) { var r = (from p in context.person bring together in context.personaddress on p.personid equals a.personid bring together e in context.personemployment on p.personid equals e.personid p.personid == personid select new vmperson { person = p, personaddress = a, personemploymenthistory = e }).firstordefault(); homecoming r; } }
c# entity-framework-6
No comments:
Post a Comment