Is it possible to use a predicate expression as a parameter for an HTTPGET request (to a mvc api controller).
Background: I`m trying to build a car rental web application. using MSsql for db, EntityFramework (code-first), a repository for (generic) CRUD functions and MVC API controller.
My aim is to send queries to db through api controller using predicate linq expression. the code:
repository:
public IQueryable<T> Search<T>(Expression<Func<T, bool>> predicate) where T : class, IDataEntity
{
return _context.Set<T>().Where(predicate);
}
api get(predicate Expression parameter) function:
public HttpResponseMessage Get(Expression<Func<Car, bool>> predicate)
{
using (IRepository Manager = Factories.Factory.GetRepository())
{
var CarList = Manager.Search<Car>(predicate)
.Select(x => new CarDTO()
{
...
})
.ToList();
return Request.CreateResponse<List<CarDTO>>(HttpStatusCode.OK, CarList);
}
}
client html angular/jq ajax request:
$http.get("/api/CarApi"+"??????",{params:{ ??????? }})
.success(function (result) {
$scope.filteredCarsList = result;
...
})
.error(function (result) {
...
});
(Im using agulars $http for ajax request, similar to $.getJSON)
Is it possible to send a predicate expression through a ajax (get) request to an api controller who expect to get a linq expression as a parameter?
if so, how? and if not, what is the correct/appropriate way to achieve my goal?