Computing service ASP.NET MVC 2 Framework

leathermumpsimusSoftware and s/w Development

Dec 13, 2013 (4 years and 7 months ago)


ADO.NET Entity Framework

With ADO.NET Entity Framework, Microsoft has done of modelado entity
relation can use
programando. It
achieves it by means of a combination of files of diagram XML, behind is the code .NET And the API of ADO.NET
Entity Framework. The files of diagram define a conceptual layer where show the warehouse of data (for
example, a database of Oracle) and create a map between the data and the objects of level of application.

ADO.NET Entity Framework Allow to write his programs using the classes that generate
from this conceptual

By defect ADO.NET Entity Framework Only is available of base for SQL Server. There Are other providers that
offer these services for his databases. The listing can consult
. Unfortunately for Oracle, all the available solutions are of payment, although there is
a commitment
by part of Oracle
to include it in a next version of the tools of development for Visual Studio
during the year 2011.

For the course have installed the solution of Devart (
) that
us his enjoy during 30 days.

Matter the model of a database

The steps are very simple, on the folder of Models, pressed right button and selecionamos Add
>New Element

We select the section Data of the left part, and the first that visualise is ADO.NET Entity Dates Model. We
select it and pressed to Add.

Computing service
ASP.NET MVC 2 Framework
We select to Generate from the database

And we defined the connection. In case that it was the first time, will press in New Connection. The next times
will remember the option selected.

We marked that it save the confidential data and put him a name to the Entity with which go to work.

After some seconds, will see that it allows us those objects that want to matter. Review that only mark that to
what has permissions of access the user.

Al the same that before put him a name to the model

If all is correct will open
a window with the tables, with his relations, and the sights.

Already we are in disposal to do use of the model mattered.

Consulting data of a table / seen

The first is to open the entity of the BD. Can do it in the own controller, out of any method.

public class HomeController : Controller



// GET: /Home/

CatalogadorEntities DB = new CatalogadorEntities();

public ActionResult Index()


return View();



Now already inside a method can do reference, for example to all the catalogues.

For this we have to know a new element that is very joined to ADO.NET Entity Framework And that the tándem
does it very powerful, LINQ.

Integrated Query (LINQ) Is an important innovation in Visual Studio 2008 and .NET Framework Version
3.5 that deletes the distance that separates the world of the objects and the world of the data.

Traditionally, the queries with data express
like simple chains, without comprobación of types in time of
n neither compatibility with IntelliSense. Besides, it is necessary to learn a language of different
queries for each type of origin of data: databases SQL, documents XML, services diverse web, etc. LINQ Convert
a query in a building of language of first class in C# and Visual Basic. The queries write
for collections of objects
with establishment inflexible of types, using key words of the language and operators with which is

For more information on LINQ consult the following page:
It is/library/bb397933(v=VS.90).aspx

We go to consult the complete catalogue of two ways

Accessing directly to the model and generating a list of all his elements

Or doing a query LINQ, without putting any condition.

Now it is the moment to create a sight. We select the model CNET_CATALOGADOR and selected that we want to
create a list

If we pressed CTRL+F5 will see the result

Since we have of the button create you, go to generate a method for the controller

We defined his
corresponding sight and left it such cual

If we visualised his result in the browser

Now it is missing us the method create you that will store the data. Simply it has to collect the data of the form,
add it to the model and save the data.

In case that it fail, go back in sight create you.

If all is correct will see that what fill up in this window, when pressing Create will see
reflected in the listing.


Universidad de Alicante

Carretera de San Vicente del Raspeig s/n

03690 San Vicente del Raspeig

Alicante (Spain)

Tel: (+34) 96 590 3400

Fax: (+34) 96 590 3464