Entity Framework 4 LINQ to Entities WCF Queries

I need to create a WCF service to return objects requested from a database through the Entity Framework. Most of the articles I read suggest that I should create a method for each type of request. But I think this will cause an explosion in the number of methods that I will create, for example:

  • GetAllCars ()
  • GetCarsByBrand (string brandName)
  • GetCarsByYear (int year)
  • GetCarsByBrandAndYear (string brandName, int year)
  • GetCarsByTireSize (float tireSize)
  • GetCarsByEngineType (string engineType)
  • GetCarsByEngineSizeAndType (float engineSize, string engineType)
  • GetCarsByEngineSizeBetween (float lowerEngineSize, float upperEngineSize)
  • etc..

Also, if a new request is required, I will have to create a new method to support it.

There should be a more general general way to do this. It would be ideal if the client can create an expression tree through LINQ, send it through WCF, and then run the request through the framework entity. Then I can have one method to support all requests. For instance:

  • QueryCars (expression)

Or send the expression as a string:

  • QueryCars (string expression)

How did the developers solve this flexible request problem?

I am currently working in .NET 4.0. Security is not really a concern, as it is just an internal application.

+3
source share
2 answers

What you are looking for are WCF data services . It uses the OData protocol to query data using Linq.

OData:

var query = from u in service.Users
            orderby u.Reputation descending
            select u;

Console.WriteLine ("Top ten Qaru users");
foreach (var u in query.Take(10))
{
    Console.WriteLine ("{0}: {1}", u.DisplayName, u.Reputation);
}

service.Users IQueryable<User>, .

SO LINQPad URL- VS.

+3

WCF, WCF. IQueryable Linq .

+3

Source: https://habr.com/ru/post/1784710/


All Articles