2

I am developing a line of business application which has to, for reasons out of my control, use a client server architecture.

I.e. clients all connect to an application server, application server connects to database etc.

To do this in the past I have created a WCF service which exposes CRUD type methods for the database. Methods like this, exist in WCF:

Customer GetCustomer(int customerId);
List<Customer> GetAllCustomers();
etc...

However I have always found the same 2 problems with this:

1) There's a LOT of plumbing code which connects: client -> app server -> db server

2) When client applications need to grab more complex data, I end up having to add methods on the server side which end up something horrible like this:

Customer GetCustomerByNameWhereCustomerHasBoughtProduct(string name, int productCode);

OR

Or returning way more data than need and processing on the client side. Which is slow and really bad for the database. Something like:

List<Customer> customers = _Service.GetAllCustomers();
List<Product> products = _Service.GetAllProducts();

List<Customer> customersWhoBoughtX = (from c in customers where   
                         c.OrderLog.Contains(products.Where(p => p.Code == x)
                         select c).ToList()

What am I doing wrong here because this must be solvable some way.

Is there a way to expose a database through a wcf service using conventions? Or any other idea that could help what I'm doing?

Ideally I would say the clients could connect to the database directly, however I am told this is an issue which can't be changed.

I would really appreciate some pointers.

Thanks

Nick Williams
  • 1,237
  • 6
  • 19
  • 40

1 Answers1

0

Consider exposing your entities using OData. Then on the client you can write LINQ queries in a way similar to writing EF LINQ queries. Here's an article with the details:

http://www.vistadb.net/tutorials/entityframework-odata-wcf.aspx

Robert Graves
  • 2,290
  • 3
  • 20
  • 24
  • Wcf Data Services are certainly a reasonable option. I've set one up as a test and I am amazed how easy it is. However it seems performance could be an issue. See here fro example :http://stackoverflow.com/questions/3916983/how-to-improve-wcf-data-services-performance. Any other alternatives or do I simply have to choose between ease of programming and performance? – Nick Williams Dec 19 '13 at 21:59