c# - Linq searching list of objects -
i have class:
public class examreviewrequested { public list<examreviewrequest> reviews { get; set;} }
it's reviews property has list of class:
public class examreviewrequest { public string eventcode { get; set; } public bool requested { get; set; } }
how search specific eventcode , return selected examreviewrequest eventcode using linq? in view, both these (row.eventcode has value want search for):
examreviewrequest er = viewbag.examreviews.single(x => x.eventcode == row.eventcode) examreviewrequest er = viewbag.examreviews.reviews.firstordefault(x => x.eventcode == row.eventcode)
return error:
cannot use lambda expression argument dynamically dispatched operation without first casting delegate or expression tree type
i've looked @ several posts concerning subject can't make of them work.
when assign examreviews
viewbag
become dynamic
object no type setting. error message telling you need cast first use linq.
what do
i can't see assign viewbag.examreviews
if it's of type ienumerable<examreviewrequest>
then:
var examreviews = (ienumerable<examreviewrequest>)viewbag.examreviews var examreviewrequest = examreviews.single(x => x.eventcode == row.eventcode)
or if it's of type examreviewrequested
then:
var examreviews = (examreviewrequested)viewbag.examreviews var examreviewrequest = examreviews.requests.single(x => x.eventcode == row.eventcode)
what should do
you shouldn't assign list<examviewrequest>
/ examreviewrequested
viewbag
. way do:
// code set model previous var examreviewrequested = model.examreviews.single(x => x.eventcode == row.eventcode);
where model
of type examreviewrequested
Comments
Post a Comment