开发者

WCF AND MVC3, system architecture. Passing a View Model with WCF?

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 acce开发者_C百科ss 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.


If I understand it correctly, you're doing your data access through WCF? If so I would return the business data (classes) through the WCF services, do the mapping to ViewModel classes via the services classes of the MVC app and then pass all the view models through to the controllers/views. Please correct me if I've misunderstood your question.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜