title: Client Server using WCF and Entity Framework
body: <p>I am developing a line of business application which has to, for reasons out of my control, use a client server architecture. </p>
  
  <p>I.e. clients all connect to an application server, application server connects to database etc.</p>
  
  <p>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:</p>
  
  <pre><code>Customer GetCustomer(int customerId);
  List&lt;Customer&gt; GetAllCustomers();
  etc...
  </code></pre>
  
  <p>However I have always found the same 2 problems with this:</p>
  
  <p>1) There's a LOT of plumbing code which connects: client -> app server -> db server</p>
  
  <p>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:</p>
  
  <pre><code>Customer GetCustomerByNameWhereCustomerHasBoughtProduct(string name, int productCode);
  </code></pre>
  
  <p>OR</p>
  
  <p>Or returning way more data than need and processing on the client side. Which is slow and really bad for the database. Something like:</p>
  
  <pre><code>List&lt;Customer&gt; customers = _Service.GetAllCustomers();
  List&lt;Product&gt; products = _Service.GetAllProducts();
  
  List&lt;Customer&gt; customersWhoBoughtX = (from c in customers where   
                           c.OrderLog.Contains(products.Where(p =&gt; p.Code == x)
                           select c).ToList()
  </code></pre>
  
  <p>What am I doing wrong here because this must be solvable some way.</p>
  
  <p>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? </p>
  
  <p>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.</p>
  
  <p>I would really appreciate some pointers.</p>
  
  <p>Thanks</p>