I have a vs2010 solution with many project (WPF control library, some business logic etc.)
Currently each library reach the WCF data services using his own Service Reference.
I’m trying to write a new library that will a some kind of a DL to the WCF data service, I want to write it using templates – so I don’t need to write the same function to all my entities (~30).
Well I’m getting nowhere..
I started by add a simple Interface like this:
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);
}
I’m trying to implement the interface and I came into issues I have no Idea how to solve
1) in the implementing class how do I tell my context which entity I’m querying
public IQueryable<Region> Where(Expression<Func<T, bool>> predicate)
{
return _context.(something general).Where(predicate);
}
2) Even if I provide the entity
public IQueryable<Region> Where(Expression<Func<T, bool>> predicate)
{
return _context.Region.Where(predicate);
}
I came into casting issues I didn’t manage to solve.
well, that’s about it.
Thank you
I’ve been experiencing by the very same problem: it is not possible to declare a WCF contract with open generic types (nor interfaces, by the way). The problem is that this framework does not adhere to some basic good OOP principles and, thus, it causes some frustration to experienced programmers.
For more information about this issue, see the example at msdn.