What datatype is returned in this Linq to SQL?
I am trying to figure out the return type. It looks like ToList () is returning a list, but I'm not sure which type.
var id = (from h in db.t_ref_harvest_type
where h.manner_of_take_id == methodOfTakeId &&
parsedSeasons.Contains((int)h.season) && h.active == true
select new { h.id, h.harvest_type }).ToList();
+3
source to share
1 answer
A List of anonymous type is returned that has id and type as a property in it.
when you write Select new in a linq query, it creates an anonymous type with the property that you specified in select new {}.
Full Access: SQL to LINQ (visual representation)
EDIT
@KeelRisk - you can't return a list of anonymous type from a method ... if you just want to return an id and then change the query select " List<int> lstid= (.....Select h.id).ToList<int>();
" and then return lstid .. do with you
List<int> lstid = (from h in db.t_ref_harvest_type
where h.manner_of_take_id == methodOfTakeId && parsedSeasons.Contains((int)h.season)
&& h.active == true
select h.id ).ToList();
+5
source to share