C# Appending Linq Queries of Same Type -
i have 2 linq queries run on 2 different tables, car , truck. these queries select id, name, , company.
var car = c in db.cars select new {id = c.id, name = c.name, company = c.company}; var truck = t in db.trucks select new {id = t.id, name = t.name, company = t.company};
how append truck data car data using linq resultant query contains both car , truck data?
if resulting types equivalent, can use enumerable.concat combine them.
however, wouldn't recommend doing anonymous types - instead i'd recommend making custom class hold 3 (or more) properties. it's possible, given code above, type may same post-compilation, it's impossible tell sure without more information.
personally, either use shared interface (ie: have car
, truck
implement icompanyinfo
properties in interface), , return car cast interface, or make custom class, , return both queries, use concat join them.
Comments
Post a Comment