I am tying to create a base class for a business layer using generics in c# 2.0. I want to have a method like:
GetList<T>(RelationPredicateBucket filter, SortExpression sorter, PrefetchPath2 prefetchPath)
That way from my businessLayer I could call:
List<MyEntity> myEntity = GetList<MyEntity>(filer, sorter, prefechPath)
and get back a strongly typed generic list instead of an EntityCollection. Here is what I have so far:
public List<T> GetList<T>(RelationPredicateBucket filter, SortExpression sorter, PrefetchPath2 prefetchPath) where T : ??EntityBase2?? //(is EntityBase2 right here? I know I need some constraint)
{
List<T> toReturn = new List<T>();
EntityCollection items = new EntityCollection(?new T'sFactory()?);//(how do I get correct EntityFactory from the type)
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
adapter.FetchEntityCollection(items, filter, 0, sorter, prefetchPath);
}
foreach (T item in items)
{
toReturn.Add(item);
}
return toReturn;
}
As you can see I have two questions. Is EntityBase2 the correct constraint? How do I get the Proper EntityFactory from the type T?
Thanks in advance.