Saltar apartados

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 layer.

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 in 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 allows 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

 Importar modelo de nuestra base de datos


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.

 Importar modelo de nuestra base de datos

We select to Generate from the database

 Importar modelo de nuestra base de datos

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.

Importar modelo de nuestra base de datos

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

 Importar modelo - Seleccionar base de datos

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

Importar modelo - Seleccionar elementos


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

 Esquema Entity Framework

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.

Language-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 compilació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 familiarised.

For more information on LINQ consult the following page: 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

Consulta tabla

Or doing a query LINQ, without putting any condition.

 Consulta tabla  - Recoger todos los elementos


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

Creación de una vista para los listados

If we pressed CTRL+F5 will see the result

Listado en el navegador


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

Añadir registros

We defined his corresponding sight and left it such cual

Creación de una vista para los añadir registros


If we visualised his result in the browser

Ficha de creación en el navegador

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.

Añadir registros

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.

Visualización en el navegador del resultado de crear registros

Computing service ASP.NET MVC 2 Framework

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

For further information:, and for enquiries on this web server:

Carretera San Vicente del Raspeig s/n - 03690 San Vicente del Raspeig - Alicante - Tel. 96 590 3400 - Fax 96 590 3464