Kutyel
Kutyel

Reputation: 9084

Develop an ASP.NET MVC Application with Web Services as the Data Access Layer

Here is the scenario:

We have a complete, functional data base with hundreds of tables and a complete self-developed API of WCF (Windows Communication Foundation) Web Services.

My mission is to develop an ASP.NET MVC Application using this services for the data interaction.

To accomplish this purpose, I know all the logic and service consumption will be at the controllers of my application which, by the way, is MVC 5.

The problem is that, as the whole database is already in production, I do not have a Model to scaffold all the Views and Controllers, and I do not know if there is a way to use the classes provided by the web services as my actual model.

ASP.NET MVC depends on EntityFramework and models defined by classes but copying the whole database into EF classes, as suggested by the DataBaseFirst approach, is not viable at all, for the database structure is so huge and I do not really need all of it for my task.

Is this possible or would it be just easier to develop a regular ASP.NET application?

Any answer or code snippet would be greatly appreciated!

Upvotes: 3

Views: 1639

Answers (2)

Gavin Coates
Gavin Coates

Reputation: 1425

ASP.NET MVC depends on EntityFramework and models defined by classes but copying the whole database into EF classes, as suggested by the DataBaseFirst approach, is not viable at all, for the database is so huge and I do not really need all of it for my task.

I'm a bit confused by your above statement. Using the database first approach will only copy the structure of the database into the application, and not the data. Additionally, this is a one of manual process, therefore it doesn't really matter how big the database is.

Once imported, you can always delete the tables that you do not need. It's as simple as selecting them in the model, and hitting delete, so it is not a particularly laborious process.

I'm a big fan of the database first style of development, but it's a personal choice, so you may find other methods more appealing based on your own preferences.

Upvotes: 1

Kristof
Kristof

Reputation: 3315

You only have to use entity framework if you want to scaffold your pages(which isn't all that helpfull).
You could use the webservice classes directly on your views or you could(and probably should) use viewmodels to submit data to your view.
An example as simple as possible would be :

public ActionResult Index(int id)
{
     var webserviceObject = webserviceProxy.GetMyObject(id);
     var vm = new MyViewModel();
     vm.Name = webserviceObject.Name;
     return view(vm);
}

your simple view would look like this :

@model MyViewModel
<html>
<body>
<h3>@Model.Name</h3>
</body>
</html>

Upvotes: 5

Related Questions