ASP.NET MVC layer separation with SQL Dapper and NHibernate

asp.net-mvc-3 dapper n-tier-architecture

Question

I am working on an ASP.NET MVC application using SQL Dapper for retrieval and NHibernate for CRUD. I am facing some problems with layer separation.

I have repositories say UserRepository which has public User GetUsersList() method. Here "User" is an NHibernate entity. The problem here is I need to display a field in the UI which is not present as a property in User like 'HasAltContacts' which I am directly retrieving from an SQL query.

Now, my question is do I need to create separate DTO's and leave these NHibernate entities and build repositories (at least READ METHODS) around these classes?

Accepted Answer

Here "User" is NHibernate entity. The problem here is I need to display a field in UI which is not present as property in User like 'HasAltContacts' which I am directly receiving from SQL query.

Define a view model that will contain all the properties your view requires. Then have your controller action populate this view model by querying the various data sources you have and pass this view model to the view.




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why