Unfortunately, I have an architecture I need to follow. For my project, we have two layers: a repository layer and a service layer.
The service layer is implemented in ASP.NET Web API. I have a method that will return all orders: GetOrders(). The method will call only one method: the repository's GetOrders(), which is implemented in Entity Framework.
I've decorated the get method with the [EnableQuery] attribute, but how can I "pass" these queryable parameters to the GetOrders() in the repository layer?
Here's some code:
Service:
[EnableQuery]
public IQueryable<Order> GetOrders()
{
return OrderRepository.GetOrders();
}
Repository:
public static class OrderRepository
{
public static IQueryable<Order> GetOrders()
{
using (OrderContext context = new OrderContext())
{
...
}
}
}
Also, the STATIC keyword is troublesome for me. Before you suggest creating a static variable of the OrderContext outside the method yet in the class, I cannot do it. My boss is a stickler for the current pattern: no static variables, etc. He wants it all contained within the method. How can I return an IQueryable, too, from the static method when I instantiate the DbContext WITHIN the method?
Thanks again, all.