I think one of your initial problems is that your ILoad interface is non-generic, but you have specified methods without generic constraints, e.g.
List<TResult> Load<TKey, TResult>(Func<TKey, TResult> select);
Firstly, predicates must evaluate to true of false, so it should really be Func<TModel, bool> select
where TModel
is your entity type.
You are then trying to do this:
List<TResult> Load<TKey, TResult>(Func<TKey, TResult> select)
{
using (Erp.DAL.ErpEntities erpEntityCtx = new Erp.DAL.ErpEntities())
{
return erpEntityCtx.Customer.Select(select).ToList<TResult>();
}
}
Without specifying any constraints on your generic methods (or better yet, your generic class), you can't satisfy the Func with Func.
You need to potentially change to this:
public interface IRepository<TModel>
{
List<TModel> Get(Func<TModel, bool> predicate);
}
And implement as:
public class CustomerRepository : IRepository<Customer>
{
public List<Customer> Get(Func<Customer, bool> predicate)
{
using (var context = new ErpEntities())
{
return context.Customers.Where(predicate).ToList();
}
}
}
You should have a read up on the repository pattern.
Matthew Abbott
2010-08-22 17:41:31