My ultimate reason of doing what I do is to provide some caching capabilities to the DbContext
. In order to achieve this, I'm trying to extend default DbSet
functionality by overriding Set<T>()
method in the context, and returning object of type that is directly derived from general DbSet
class. Like this:
public class Context : DbContext
{
...
public override DbSet<TEntity> Set<TEntity>()
{
//var set = base.Set<TEntity>();
var set = new XxSet<TEntity>();
return set;
}
}
class XxSet<TEntity> : System.Data.Entity.DbSet<TEntity>
where TEntity : class
{
public override TEntity Find(params object[] keyValues)
{
return base.Find(keyValues);
}
}
Looks clear and simple, but when I run my tests on this, EF gives me an error:
The member 'IQueryable.Provider' has not been implemented on type 'XxSetˊ1' which inherits from 'DbSetˊ1'. Test doubles for 'DbSetˊ1' must provide implementations of methods and properties that are used.
It asks me to implement IQueryable interface. That's I see, but why? Shouldn't it already be implemented in the base class?
I guess it must, otherwise, how would work the base functionality of Set<T>()
method, which is returning object instantiated by System.Data.Entity.DbSet<TEntity>
type.
Am I missing something here?
BTW. I know about Microsoft example of creating in-memory DbSets. I just want to understand why can't I do this simple way.