We have a legacy site that was written a while back using MVC. It's a valid MVC for the most part except for the Data Access Layer. The site has Models, Views, and Controllers. However, instead of using Entity Framework, they use web services that use ADO to execute stored procedures.

For example: say we have a page to display all users. We'd have a users.cshtml view, a UsersController.cs class, and a UserViewModel.cs class.

The GetUsers() method in the Users controller would call a web service method called WebService.GetUsers(). This web service would then call a stored procedure named dbo.GetUsers which would contain something like select * from Users where Active = true.

I've never seen this type of approach before and was wondering if it was something that was made up by whoever made this site, or if it's an architecture style from the past?

I would also like to know if this is a good architecture to use.

有帮助吗?

解决方案

Sure, this is perfectly valid. It all depends on the specific use case.

If there are multiple applications which utilize the web service then it makes sense to split that data access layer out into something that multiple applications can reach as opposed to implementing it directly in the MVC site. As far as the difference between using EF and stored procedures go, this is all preference. Their staff very well may have had more expertise in SQL/stored procedures than entity framework in which case it may make sense to use stored procedures.

Personally, I prefer entity framework as well but architecturally, it makes little difference what specific tool you use to query your SQL db. As a side note, it doesn't mean the app is not "valid MVC" just because they aren't using entity framework.

If it is just one app querying the db for data then I would've opted to keep things simple and implement the data layer in the same solution as the current MVC code as I opt to keep things simple when I can. If there's a chance that there will be mobile apps, etc in the future that need to pull data from the db, then I'd implement a web service that pulls data from the db via entity framework but again, the tool you're using to query the db is going to vary pretty greatly from company to company- there are a bunch of ORMs like entity framework and I've seen quite a few companies writing raw parameterized SQL queries in their data access layer.

I hope that helps.

许可以下: CC-BY-SA归因
scroll top