Thursday, December 3, 2009

In Sims 3 Where Is The Relic Of Eternity

Reloaded Run 2009 - Part II

Entity Framework 4

Continuing the series of post about the new benefits of VisualStudio 2010, some of which were presented by experts in the Run Reloaded 2009, is the turn of treating one of progress. according to my taste, but interesting in this new version of Visual Studio and Entity Framework. This post is based on very good chat with Daniel Laco introduce improvements in the Entity Framework 4 Reloaded Run 2009.
is possible that this product is one of the most imortant upgrade to VS 2010 as previously this did not come integrated into the IDE and AHRO if this
, this product actually just now acquires an interesting dimension, because the versions earlier had much to do, and everything is finally coming to light in this version, Entity Framework 4 is good news for Microsoft, bearing this version number to match that of other products (C # 4.0, etc), as previously knew the version 1. I'll make an exception at this point and remember for those who know and those not present, at one time much of the community of professionals related to this product from Microsoft, had issued a vote of no confidence, expressing their dissatisfaction Entity Framework with product 1 and the features aimed directly at which he was covered, by the time the team developing EF4 echoed this request and will cover the items that demand. can see the ADO. NET Entity Framewor Vote of NO CONFIDENCE HERE. Particularly
me very interested in the development of the Entity Framework since its first release and I'm pretty satisfied at least at the moment prior to its evolution.

A little history ... And in the beginning were only databases

Well to talk about the Entity Framework (from here on but I am going to use EF as abbreviation), we must first address synthetically why this whole thing, and why is a little on the type of software that pretends to be (I think now with some more successful than its predecessor versions, but not as much as it should) and this is an ORM (ORM English Object - Relational Mapping Mapping or Object - Relational in English), this software is to try to save a fairly automated impedance that exists between the concepts on which to lay the relational database and software development paradigm of object-oriented. In a nutshell this type of framework is to provide a solution to the problem of what to do to reconcile two dissimilar worlds: the world of tables, triggers, stored procedures and the views and objects with which we model the domain of a problem that our system solves software. In advance I want to clarify that ORMs are not the only solution to this problem as there are databases object-oriented (as db4objects which is very good!) I this clarification to not open a debate about which is the best option, which to me is very specific case, I do not want to think that this project does not use an ORM is worse than another, if vice versa. The ORMs are nothing more than another solution for the same problem.
Now we know to serve or that EF will help us, we must clarify that the ORM are intensive in the Java world, of all Hybernate stands out for its widespread use, and this extension came to the universe. net through its version for this Nhybernate. Hybernate is something like the king of the ORM, in EF hand has a long way to go, at least for me.
It is the intention of this post on a tour from scratch and deep on EF or the ORM, I'm going to do here is a description of the improvements introduced by EF 4, ie off that anyone reading this article, has a practical or theoretical knowledge, basic use of this tool.
Now if we go into the world of ORM specifically Entity Framework 4.
To carry out tests with code or to follow the examples that I will raise, must have Visual Studio 2010 Beta 2, which can (and heartily recommend) download from HERE . You must download the Microsoft ADO . NET Entity Framework Feature Community Technology Preview 2 HERE.
Let's see some of the major changes included in this new version of EF4:
Support
  • POCO (Plain Old CLR Objects), Persistence Ignorance and tracking Change
  • T4 Code generator
  • Soort Complex Type
  • Lazy Loading
  • Model - First Development
  • pluralization Self
  • Entities and support tracking N - Layers
Class Generation
Once we have designed an Entity Data Model, the designer fires a code generator that creates classes from the entities defined in the model, the Entity Framework first version of this code was run by System.Data.Entity.Design API, if you wanted to customize the code generation should study the API and create our own methods of generation that was really annoying. To EF4, using a code generator called T4 (Text Template Transformation Toolkit, introduced in Visual Studio 2008). Using T4
customize class generation from entities in the model is much simpler. VS 2010, no editor has a built-T4, but there are numerous third-party publishers are integrated with the IDE, I have installed the Tangible T4 Editor, which can be installed, if the IDE go to Tools -> Extension Manager, a Once there we went to select Tangible T4 Gallery Online Editor, we downloaded, installed and restart the IDE. Modifying the generation of classes from the model is a matter of modifying the template file is tt. I will not expand here on how to modify the template T4 because I will dedicate a post next only to this tool.

Lazy Loading
EF4 In this version finally includes this option that is present in many ORM, in a nutshell this means that when I bring for example from the database a set of Customer entities, which In turn, each customer has orders, just bring the entities Customer and if required at a later stage then I can bring to a specific customer orders, ie a demand model, the new EF4 this is achieved through of a new property of ObjectContext, as in the following line of code:

this.ContextOptions.LazyLoadingEnabled = true;

By default this option is false. One thing to keep in mind when using lazy loading is that EF, to undertake further consultations to bring the orders for each customer, this should be evaluated in depth since each time a customer must bring their orders involves a round trip to the database to retrieve the requested data. Support

POCO (Plain Old CLR Objects)
By default, classes derived from the model inherited from EntityObject, this provides the necessary mechanisms for the functionality of ORM. But there are developers who prefer to create simple classes that are not strongly linked to the framework. One of the major improvements in EF4 is that it allows developers to create simple classes (POCO) can still be used with EF, consider the following code:
 

public class Course {public int
CourseID {get, set;
} public string Title {get, set;} public string
Days {get; set;} public DateTime
Time {get, set;}
public string Location {get, set;} public int
Credits {get, set;
} public Department Department {get, set;}}


public class Department {public int
DepartmentID { get; set; }
public string Name { get; set; }
public decimal Budget { get; set; }
public DateTime StartDate { get; set; }
public int Administrator { get; set; }
public List Courses { get; set; }
}
public class SchoolEntities : ObjectContext
{
private ObjectSet _departments;
private ObjectSet _courses;
public ObjectSet Departments
{
get
{
return _departments;
}
}

public ObjectSet Courses
{
get
{
return _courses;
}
}
public SchoolEntities()
: base ("name = SchoolEntities", "SchoolEntities) {

CreateObjectSet _departments = ();
CreateObjectSet _courses = ();
}}


Here we see the conventions we must continue to use simple classes with our EF, we have two simple classes such as Course and Department entities have the same EF, then SchoolEntities is our class context, which should be placed on the same project as the EF model, but can be referenced classes who are another assembly.
far I have tried to name, discuss and explain in some cases some of the new Entity Framework 4. In a next post I will make a fine example 100% practical and much code from scratch, as this tool is warranted.
I leave some interesting links for the final
ADO. NET team blog (team responsible for developing the Entity Framework 4).
Diego Vega's Blog (Program Manager in the Entity Framework Team at Microsoft).

With this I leave to the next post. Happy programming for everyone!

0 comments:

Post a Comment