c# - Foreign key to values using Linq -
i have webpage , site using linq. page contains gridview shows customers , bound list (of customer).
i use below code single customer
public function getcustbyid(byval id integer) customer implements icustomerservice.getcustbyid return datacontext.customers.singleordefault(function(c) c.id = id) end function
i bind gridview passing customer ids method. displays rows need have 1 issue.
some columns foreign keys show 1,2 etc, way have overcome in past on different projects adding sub query sql query in data layer you've guessed linq im not sure /not possible in order foreign keys display values using linq?
im little new linq appreciate or articles me this.
thanks
it recommended separate view entity classes (or domain classes if like). define view model class, customerviewmodel
, , project customer
it.
i'm not sure how list of customers (getting each single customer id highly inefficient) somewhere there ienumerable<customer>
. let's call customers
. can do
from c in customers_ select new customerviewmodel { name = c.name, ... }
but can add properties customerviewmodel
not in customer
! instance
select new customerviewmodel { name = c.name, typename = c.customertype.name }
this customertype
1 of foreign keys want show.
the result of projection ienumerable<customerviewmodel>
can show in grid.