I am trying to get a list of all the objects in a database of the specified type. I did this before when the type was known at compile time, but now I am trying to pass the type to the method and return the method to all the records of this specified type, and I cannot get it to work. I tried the following:
public IList<WritingObject> GetBasicObjectsByProject(int projectId, Type oType) { var results = from o in _objects.AsQueryable where o.Project.Id == projectId && o.GetType() == oType select o; return results.ToList<WritingObject>(); }
This did not work because Linq to Entities does not support the GetType () method. Then i tried
var results = from o in _objects.AsQueryable where o.Project.Id == projectId && o is oType select o;
This does not work because the compiler claims that oType does not have a known type. Using typeof(oType) causes the same error as executing OfType<oType>() on IQueryable .
I'm running out of ideas to preserve this dynamic without breaking it down into one method for each subtype. Does anyone have any ideas?
source share