c# - Getting error in LINQ Expression or converting service to client simple mapping -
getting error
"system.linq.enumerable+whereselectenumerableiterator`2[person.models.iprofession,system.string]"
code below: trying have collection of result. service returns me collection think , need iterate through , store list have collection. please me
public class professionresult { public string name { get; set; } public string id{ get; set; } } public list<professionresult> professionresults { { var professionresults = new list<professionresult>(); professionresults.add(new professionresult() { name = people?.where(p => p.isselected) .select(c => c.professionresults.select(n => n.name)) .tostring() ?? null, id = people?.where(p => p.isselected) .select(c => c.professionresults.select(i => i.id)) .tostring() ?? null }); return professionresults; } }
a basic google search on partial error message revealed post: linq query on xdocument returns "system.linq.enumerable+whereselectenumerableiterator'2[system.xml.linq.xelement,system.string]
according it,
yes, that's because you've calling tostring() directly on query second , third values.
basically, don't call tostring() on queries. if want single value, use single(), first() etc. if want multiple values, iterate on them , want each of them in turn - or join them in appropriate fashion.
which means have store values initial format , not use tostring()
on them inside linq query.
*edit**
for example, try:
name = people?.where(p => p.isselected).select(c => c.professionresults.select(n => n.name)).single().tostring() ?? null, id = people?.where(p => p.isselected).select(c => c.professionresults.select( => i.id)).single().tostring() ?? null
but if know for sure return single unique record p => p.isselected
every time.
i haven't tested it, let me know if works.
Comments
Post a Comment