I'm looking to implement a repository pattern with breeze EFContextProvider. In this repository, I would expose a method to query the DB using OData filtering... just as breeze behaves by default. I would also want to expose a method that would ignore OData filtering, and return a list of elements as if it was the default EF Context.
So, to sum up, my idea would be to try to do something like this:
public class RepositoryBaseEntity<T> : IRepository<T> where T : class
{
protected Breeze.WebApi.DataModelContainer _context;
public RepositoryBaseEntity(Breeze.WebApi.EFContextProvider<DataModelContainer> context)
{
_context = context;
}
/// <summary>
/// Gets all elements, ignoring OData filtering
/// </summary>
/// <returns>All elements, or null if none exists</returns>
public IEnumerable<T> GetAll()
{
// disable OData filtering in Breeze.WebApi.EFContextProvider
return _context.Context.Set<T>();
}
/// <summary>
/// Apply ODataFilters and get elements. Useful for Web API controllers
/// </summary>
/// <returns></returns>
public IEnumerable<T> ApplyODataFiltersAndGet()
{
// enable OData filtering in Breeze.WebApi.EFContextProvider
return _context.Context.Set<T>();
}
}
I've been taking a look at Breeze EFContextProvider, and there doesn't seem to be a way of disabling OData filtering.
I've though about maybe using the plain old Entity Framework DataModelContainer when I don't want OData filtering, and using Breeze EFContextProvider wrapper when I do want OData filtering... but using this approach I would have two EF contexts... and that's something i want to avoid... in the past in some other projects we've had some problems using more than one EF contexts.
So, you guys see any way of doing this? Thanks!