You give the example:
var x = acDAL.GetData();
foreach(var a in x) {
int id=a.Id;
}
But most if that will already work, especially since IQueryable implements IEnumerable. The problem is the .Id
You have two choices there:
- know the T, and cast to IQueryable-of-T
- use dynamic
The latter only involves changing the var
in your example to dynamic
:
var x = acDAL.GetData();
foreach(dynamic a in x) {
int id=a.Id;
}
The former involves knowing the object - try a.GetType() to see what it is. Then:
var x = acDAL.GetData();
foreach(SomeType a in x) {
int id=a.Id;
}
Or alternatively:
var x = (IQueryable<SomeType>)acDAL.GetData();
foreach(var a in x) {
int id=a.Id;
}