i have 2 tables in sql database named computer , department in have 1-to-many relationship through table named departamentcomputer (pk computerid).
i trying list computers respective department name on datagridview when comes department on datagridview shows entity instead of name of department this: datagridview row
these methods required computers generic repository:
public task<list<tentity>> getallasync() { return context.set<tentity>().tolistasync(); } public async task<ienumerable<computadora>> listarasync() { return await _unitofwork.computadora.getallasync(); }
and these methods populate datagridview
private async void listarcomputadoras() { var lista = await listarasync(); popular(lista); } public void popular(ienumerable<computadora> computadoras) { var bs = new bindingsource() {datasource = computadoras.tolist()}; dgvdatos.datasource = bs; }
how can select property name of table department , show on datagridview instead of showing name of entity?
thank you!
edit: forgot mention. want avoid use of anonymous types because have more logic depends on list of computers , anonymous types logic break.
try this
public void popular(ienumerable<computadora> computadoras) { var data = (from c in computadoras select new { codigointerno = c.codigointerno, departamento = c.departamento.name, // if department entity has name property. // assign properties shown in grid }).tolist(); var bs = new bindingsource() {datasource = data}; dgvdatos.datasource = bs; }
if don't use anonymous type, create class required properties , use follows.
public void popular(ienumerable<computadora> computadoras) { var data = (from c in computadoras select new computer{ codigointerno = c.codigointerno, departamento = c.departamento.name, //if department entity has name property. // assign properties shown in grid }).tolist(); var bs = new bindingsource() {datasource = data}; dgvdatos.datasource = bs; } public class computer { public string codigointerno {get;set;} public string departamento {get;set;} //add properties here }
Comments
Post a Comment