This is because you are returning an
anonymous
type from your
Select
and you are trying to store it in the
List<eventgroup>
. The projections always create anonymous types.
Also, if you only need to have
ID
and
name
in the results why are you storing them in a list of
List<eventgroup>
. using
var
should be fine. If you must have the result in the
List<eventgroup>
then there is something wrong and you might want to reconsider the logic/design.
If you don't want to use var then you will have to utilize the fact that utlimately whatever is being returned is enumerable. so try this and this should work.
IEnumerable eventt_grp = lstGroup.Select(r => new {r.ID, r.Name });