title: WCF AND MVC3, system architecture. Passing a View Model with WCF?
body: <p>I am using Entity Framework, Linq, WCF and MVC3. The system has been split into a tier approach and I am using WCF because multiple systems will be using the same Data Access and Business Logic.</p>
  
  <p>Data Access – Business Logic – API (WCF) – Service Classes – MVC</p>
  
  <p>For each View in my MVC application, LINQ queries need to be wrote which access different tables in the database and show summaries as seen below.</p>
  
  <pre><code>        var users =
             (from u in _userRepository.All
              from upd in u.UserPropertyData.DefaultIfEmpty()
              from upd1 in u.UserPropertyData.DefaultIfEmpty()
              where (upd.UserPropertyType.Alias == "Forename") &amp;&amp; (upd1.UserPropertyType.Alias == "Surname")
              select new UserModel
              {
                  Id = u.Id,
                  Forename = upd.Value,
                  Surname = upd1.Value,
                  EmailAddress = u.Email
              });
  </code></pre>
  
  <p>This query is in my Business Logic section and is passing a UserModel across my WCF API to my Service class which passes the Model to my Controller which is then displayed in a View.</p>
  
  <p>This approach doesn’t seem correct because the Data Access and Business Logic are being coupled to MVC by passing back a ‘View Model’. If anyone can think of a better approach I would appreciate it.</p>