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 http://msdn.microsoft.com/en-us/dates/dd363565.aspx. 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.
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.
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()
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: