I have a LINQ query in function, like below code:
public object RetrieveFday(DateTime _dt)
{
var fp = from f in RSC.tbl_FoodPlan join food in RSC.tbl_Food
on f.FoodID equals food.FoodID
where f.Day == _dt
select new
{
FoodName= food.Name,
Fholiday= f.HoliDay
};
return fp;
}
now I call this function in other place, I want to get result and separate them to display every one in different label, when call the function and get result I cant read property of them:
var test = RetrieveFday(dt);
how can read the property in result that into test?
Anonymous types are not meant to use as a return types, so just create a new class to hold your projection data:
And modify your
RetrieveFdayfunction to use your class in theselect:And you can then use your function like: