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.
Data Access – Business Logic – API (WCF) – Service Classes – MVC
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.
var users =
(from u in _userRepository.All
from upd in u.UserPropertyData.DefaultIfEmpty()
from upd1 in u.UserPropertyData.DefaultIfEmpty()
where (upd.UserPropertyType.Alias == "Forename") && (upd1.UserPropertyType.Alias == "Surname")
select new UserModel
{
Id = u.Id,
Forename = upd.Value,
Surname = upd1.Value,
EmailAddress = u.Email
});
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.
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.