I have a external DLL with my classes and I would like to make the query depending on the type. I explain better.
I get the type with the function GetType:
Type targetType = Type.GetType("...");
If there is any way to make a select like this:
_context.Set<targetType>().ToList()
Assuming that _context is my DBContext.
Thanks
Indeed there is:
var method = typeof(DbContext).GetMethod("Set").MakeGenericMethod(targetType);
var query = method.Invoke(ctx, null) as IQueryable;
var list = query.OfType<object>().ToList();
Well i did something like that.
Here is an example
Public class repository: dbcontext
{
public IDbset<car> Cras {get; set;}
Public IQueryable<T> Get<T>()
{
return this.gettype().getproberties().find(x=>. x.propertytype== typeof(T)). Getvalue(this) as IQueryable<T>;
}
}
Hop this get you started. Writen from moble :)