我有一个包含许多项目(WPF 控件库、一些业务逻辑等)的 vs2010 解决方案。目前每个库都使用自己的服务参考来访问 WCF 数据服务。我正在尝试编写一个新库,它将对 WCF 数据服务提供某种 DL,我想使用模板编写它 - 所以我不需要为我的所有实体编写相同的函数(~30) . 好吧我无处可去..
我首先添加了一个简单的界面,如下所示:
public interface IRepository<T>
{
IQueryable<T> GetAll();
T GetSingle(int id);
IQueryable<T> FindBy(Expression<Func<T, bool>> predicate);
IQueryable<T> Where(Expression<Func<T, bool>> predicate);
void Add(T entity);
void Delete(T entity);
void Update(T entity);
}
我正在尝试实现接口,但遇到了我不知道如何解决的问题
1)在实现类中我如何告诉我的上下文我正在查询哪个实体
public IQueryable<Region> Where(Expression<Func<T, bool>> predicate)
{
return _context.(something general).Where(predicate);
}
2) 即使我提供实体
public IQueryable<Region> Where(Expression<Func<T, bool>> predicate)
{
return _context.Region.Where(predicate);
}
我遇到了我无法解决的选角问题。
好吧,就是这样。谢谢