I need my implementation of IObjectSet<T>
to be able to validate expressions as the "real" Linq2Entity provider would. Is it possible?
Background:
I've changed my EF model (model-first) to return IObjectSet<T>
instead of ObjectSet<T>
So that I can fake my model, and have it return the data I want.
Problem:
I have written an implementation of IObejctSet<T>
that is bacally a wrapper for a List<T>
.
This is all good - but when I query my implementation of IObjectSet<T>
im using LinqToObject - so there is no guarantee that I have valid Linq2Entity expression.
Proposed solution:
use the real
In my implementaion i just use List<T>
's provider:
private class IObjectSetUnitTestImplementation<T> : IObjectSet<T> where T : EntityObject
{
private IQueryable _qry;
public IObjectSetUnitTestImplementation(List<T> lst)
{
_inner = lst;
_qry = _inner.AsQueryable();
Expression = _qry.Expression;
ElementType = _qry.ElementType;
Provider = _qry.Provider; //<--should be ObjectSet<T>'s provider
}
//Rest of implementaion omitted
}
So I tried this:
ObjectContext context = null;
var _qry = new ObjectQuery<T>(typeof(T).Name, context) as IQueryable;
Expression = _qry.Expression;
ElementType = _qry.ElementType;
Provider = _qry.Provider;
But I have no context to feed it with, and even if I had, it would just try to access the database.
Is there any other way?