c# - how concatenate multiple rows in LINQ with two tables? -
i try concatenate multiple rows in single row 2 tables 1 of them has foreing key
i have tables:
table printer:
printerid name description -------------------------------- 1 printer1 description1 2 printer2 description2
table resolution:
resolutionid measure printerid -------------------------------- 1 123 1 2 234 1 3 345 2 4 456 2
i need in gridview:
printerid name description resolution ------------------------------------------------------------------------ 1 printer1 description1 123, 234 2 printer2 description2 345, 456
i have code stuck
var printer = tprinter in context.printer join tresolution in context.resolution on tprinter.printerid equals tresolution.printerid collection2 subcase2 in collection2.defaultifempty() tprinter.disabledate == null select new { tprinterprinterid = tprinter.printerid, tprintername = tprinter.name, tprinterdescription = tprinter.description, tcountryname = tprinter.city1.state.country.name, tstatename = tprinter.city1.state.name, tcityname = tprinter.city1.name }; return printer
a join creates row each combination of printer , resolution. think want select in subquery.
var printer = tprinter in context.printer tprinter.disabledate == null select new { tprinterprinterid = tprinter.printerid, tprintername = tprinter.name, tprinterdescription = tprinter.description, tcountryname = tprinter.city1.state.country.name, tstatename = tprinter.city1.state.name, tcityname = tprinter.city1.name, resolution = context.resolution.where(r => r.printerid == tprinter.printerid) }; return printer;
once you've done tolist()
out of database, can string.join(", ", printer.resolution)
create comma delimited list.
Comments
Post a Comment