c# - how to join two table column name and yield one result in linq -
need clear 1 doubt on linq
public list<selectlistitem> getattributename() { var attri = (from z in _entities.attributes select z).asenumerable() .select(z => new selectlistitem { text = z.attributename + " (" + z.attributetype.attributetypecode + ")", value = z.attributeid.tostring() }); return attri.tolist(); }
on line
text = z.attributename + " (" + z.attributetype.attributetypecode + ")",
the output be.. this..
abcd (efgh) ijkl(mnop) qrst(uvwx)
but need output is
abcd ijkl qrst efgh mnop uvwx
how achieve that..?
public list<selectlistitem> getattributename() { return _entities.attributes .select(a => new selectlistitem { text = a.attributename, value = a.attributeid.tostring() }) .concat(_entities.attributes.asenumerable() .select(a => new selectlistitem { text = a.attributetype.attributetypecode.tostring(), value = a.attributeid.tostring() }) .tolist(); }
or in single query database (previous sample query database 2 times):
public list<selectlistitem> getattributename() { var attributes = _entities.attributes .select(a => new { a.attributename, a.attributetype.attributetypecode, a.attributeid }).tolist(); return attributes.select(a => new selectlistitem { text = a.attributename, value = a.attributeid.tostring() }) .concat(attributes.select(a => new selectlistitem { text = a.attributetypecode.tostring(), value = a.attributeid.tostring() }) .tolist(); }
Comments
Post a Comment