views:

36

answers:

3

i try to write manager class. But i can not use that :

return erpObj.Get(predicate); 
How can i do that?



namespace Erp.BLL.Manager
{

    public interface ILoad
    {
        List<TResult> Load<TKey,TResult>(List<TKey> list, Func<TKey, TResult> select);
    }

    public interface IRepository<TModel>
    {
        List<TModel> Get(Func<TModel, bool> predicate);
    }

    public interface IErpManager
    {
       List<TResult> Load<TKey,TResult>(ILoad erpObj, List<TKey> list, Func<TKey, TResult> select);
       List<TModel> Get(IRepository<TModel> erpObj, Func<TModel, bool> predicate);
    }

    public class ErpManager : IErpManager
    {

        #region IErpManager Members

        public List<TResult> Load<TKey, TResult>(ILoad erpObj, List<TKey> list, Func<TKey, TResult> select)
        {
            return erpObj.Load(list, select);
        }

        public List<TModel> Get(IRepository<TModel> erpObj, Func<TModel, bool> predicate)
        {
            return erpObj.Get(predicate);
        }

        #endregion
    }



}
A: 

I don't know what is the implementation of IRepository or what you are using as DAL and you didn't even specify what problem you have, but usually in LINQ you use predicates like that:

Expression<Func<TModel, bool>> predicate

so

public interface IRepository<TModel>
{
    List<TModel> Get(Expression<Func<TModel, bool>> predicate);
}
Necros
A: 

At a glance you need to specify the generic arg on the Get method on your ErpManager

public List<TModel> Get<TModel>(IRepository<TModel> erpObj, Func<TModel, bool> predicate)
    {
        return erpObj.Get(predicate);
    }

this also has to be reflected on your IErpManager interface.

aqwert
A: 

You need to add the template type to each Get() method:

    public interface IRepository<TModel>
    {
        List<TModel> Get<TModel>(Func<TModel, bool> predicate);
    }

    public interface IErpManager
    {
        List<TResult> Load<TKey, TResult>(ILoad erpObj, List<TKey> list, Func<TKey, TResult> select);
        List<TModel> Get<TModel>(IRepository<TModel> erpObj, Func<TModel, bool> predicate);
    }

ErpManager:

        public List<TModel> Get<TModel>(IRepository<TModel> erpObj, Func<TModel, bool> predicate)
        {
            return erpObj.Get(predicate);
        }

This will actually compile.

devio