I have Repository<T>
where T
is derrived form of BaseEntity
class. Repository<T>
has IQueryable<T> Table
property. I need to make a call to FirstOrDefault
method in the Table
property.
till now i have got to list the Repositories, but stuck making call to the method using reflection.
private IEnumerable<object> GetEnumerableRepositoryOf<T>(params object[] constructorArgs) where T : class
{
List<object> objects = new List<object>();
foreach (Type type in
Assembly.GetAssembly(typeof(T)).GetTypes()
.Where(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof(T))))
{
objects.Add(Activator.CreateInstance(typeof(Repository<>).MakeGenericType(type), constructorArgs));
}
return objects;
}
var repoList = GetEnumerableRepositoryOf<BaseEntity>(constructorArgs);
foreach (var repo in repoList)
{
// call FirstOrDefault() here
}
Aucun commentaire:
Enregistrer un commentaire