【发布时间】:2012-04-19 09:44:14
【问题描述】:
我有一个包含许多项目(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);
}
我遇到了无法解决的选角问题。
嗯,就是这样。 谢谢
【问题讨论】:
标签: asp.net wcf rest wcf-data-services