开发者

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

开发者 https://www.devze.com 2023-04-12 02:54 出处:网络
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.

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

精彩评论

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

关注公众号