c# - How to return a object properties through a Result -



c# - How to return a object properties through a Result -

i trying properties of object. not sure how type of relationship using. returning of jobs in db. jobs has one-to-many relationship customeremployee class. need of properties in customeremployee class accessible through job list. have managed first & lastly name of customeremployee don't see how can access other properties using way. don't know if need alter way have relationship setup? leads me next question, when create new job post, foreign key not beingness inserted in right column. db has 2 different columns.example, "jobtespmid" & "jobtespmid_employeeid". need id inserted in "jobtespmid_employeeid" beingness inserted in other one. got kind of lost when setting understand why happening.

public class job { public int64? jobid { get; set; } public int? jobnumber { get; set; } public string jobname { get; set; } public string jobdescription { get; set; } public int? geoareaid { get; set; } public virtual jobmisc.geoarea geoarea { get; set; } public int? jobclassid { get; set; } public virtual jobmisc.jobclass jobclass { get; set; } public int? jobtypeid { get; set; } public virtual jobmisc.jobtype jobtype { get; set; } public int64? customerid { get; set; } public virtual client customer { get; set; } public virtual icollection<changeorder> changeorders { get; set; } public virtual icollection<purchaseorder> purchaseorders { get; set; } public virtual icollection<jobitem> jobitems { get; set; } public int? customeremployeepmid { get; set; } public virtual customeremployee customeremployeepm { get; set; } public int? customeremployeeadminid { get; set; } public virtual customeremployee customeremployeeadmin { get; set; } public int? customeremployeeaccountantid { get; set; } public virtual customeremployee customeremployeeaccountant { get; set; } public int? customeremployeesuperintendentid { get; set; } public virtual customeremployee customeremployeesuperintendent { get; set; } public int? jobtespmid { get; set; } public virtual employee jobtespm { get; set; } public int? jobtessuperintendentid { get; set; } public virtual employee jobtessuperintendent { get; set; } }

customeremployee

public class customeremployee { [key] public int customeremployeeid { get; set; } public string customeremployeefirstname { get; set; } public string customeremployeelastname { get; set; } public string customeremployeeemail { get; set; } public int64? customeremployeephonenumber { get; set; } public int64? customeremployeecellnumber { get; set; } public int64? customeremployeefaxnumber { get; set; } public bool? customeremployeeishidden { get; set; } public string customeremployeerole { get; set; } public int64? customerid { get; set; } public virtual client customer { get; set; } }

viewmodel/result

public class jobviewmodel { public int64? jobid { get; set; } public int? jobnumber { get; set; } public string jobname { get; set; } public decimal? joboriginalcontract { get; set; } public datetime? jobcontractdate { get; set; } public decimal? jobtotalco { get; set; } public decimal? jobrevisedcontract { get; set; } public decimal? joboriginalbudget { get; set; } public string jobstatus { get; set; } public bool? jobtaxexempt { get; set; } public bool? jobcertpayroll { get; set; } public decimal? jobcost { get; set; } public decimal? jobremainingbudget { get; set; } public decimal? jobprofit { get; set; } public decimal? jobpercentage { get; set; } public decimal? jobtotalbilled { get; set; } public decimal? jobbalancetobill { get; set; } public decimal? jobpaidtodate { get; set; } public decimal? jobbalancedue { get; set; } public bool? jobishidden { get; set; } public string client { get; set; } public string customeremployeepm { get; set; } public string jobtespm { get; set; } public string jobtessuperintendent { get; set; } public ienumerable<changeorder> changeorders { get; set; } public ienumerable<purchaseorder> purchaseorders { get; set; } } public class jobresult { public int64? jobid { get; set; } public int? jobnumber { get; set; } public string jobname { get; set; } public decimal? joboriginalcontract { get; set; } public datetime? jobcontractdate { get; set; } public decimal? jobtotalco { get; set; } public decimal? jobrevisedcontract { get; set; } public decimal? joboriginalbudget { get; set; } public string jobstatus { get; set; } public bool? jobtaxexempt { get; set; } public bool? jobcertpayroll { get; set; } public decimal? jobcost { get; set; } public decimal? jobremainingbudget { get; set; } public decimal? jobprofit { get; set; } public decimal? jobpercentage { get; set; } public decimal? jobtotalbilled { get; set; } public decimal? jobbalancetobill { get; set; } public decimal? jobpaidtodate { get; set; } public decimal? jobbalancedue { get; set; } public bool? jobishidden { get; set; } public string client { get; set; } public string customeremployeepm { get; set; } public string jobtespm { get; set; } public string jobtessuperintendent { get; set; } public ienumerable<changeorder> changeorders { get; set; } public ienumerable<purchaseorder> purchaseorders { get; set; } }

apicontroller

// api/<controller> public ienumerable<jobresult> get() { using (var context = new applicationdbcontext()) { homecoming context.jobs .include(x => x.customer) .include(x => x.changeorders) .include(x => x.purchaseorders) .include(x => x.customeremployeepm) .include(x => x.jobtespm) .include(x => x.jobtessuperintendent) .toresults(); } }

json

0: {$id: "1", jobid: 2, jobnumber: 3244, jobname: "job alpha", joboriginalcontract: 34343443,…} $id: "1" changeorders: [,…] customer: "twin peaks" customeremployeepm: "kelly young" jobid: 2 jobname: "job alpha" jobnumber: 3244 jobtespm: "laura mince" jobtessuperintendent: "scott willis" jobtaxexempt: true jobtotalbilled: null purchaseorders: [] 1: {$id: "3", jobid: 9, jobnumber: 342, jobname: "sad", joboriginalcontract: 323232,…}

return context.jobs .include(x => x.customer) .include(x => x.changeorders) .include(x => x.purchaseorders) .include(x => x.customeremployeepm) .include(x => x.jobtespm) .include(x => x.jobtessuperintendent) .tolist();

is need

c# asp.net-web-api2 asp.net-mvc-5.1 asp.net-mvc-viewmodel

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -