i have a simple question about entity .
i have a simple method it makes simple inner join between two table in db ,
now returned type is anonymous i think ,
if i use IEnumerable like below it works fine and when i fill datagridview it works good but how can i move between IEnumerable and retrieve my object because their are anonymous types and we can not use this:
foreach(var o in result)
o.Id //did not have a type and is not accessible
????? Testmethod()
{
IEnumerable<object> result;
using (var context = new TestDBEntities())
{
result = (from a in context.Table1
join b in context.Table2
on a.ID equals b.Id
select new { b.Id ,b.name });
}
return ???
}
You cannot pass anonymous types between methods (well you can, but not strongly typed and it would be a bad workaround at best). Best approach is to define a simple class for this that you can use in your projection:
Now you can use
Fooin your query and return anIEnumerable<Foo>as result: