8.2. Why Use EF?

The following sections cover the benefits of using an ORM solution, although please note that some of these advantages are not EF-specific—excellent (and more mature) alternatives do exist. Probably the best-known and one of the most mature ORM solutions in the .NET world is NHibernate. You can, however, view an extensive list at http://en.wikipedia.org/wiki/List_of_object-relational_mapping_software.

8.2.1. Abstraction

Data is generally held in a relational manner that is optimized for storage and quick retrieval (well, in most cases it should be). However, this format tends to not map that easily to how we want to work with the entities involved. ORM solutions can provide a conceptual mapping that allows you to organize your entities and their properties in a manner that is different than how they are physically stored.

For example, I worked on an application for a hospital that stored data about patients in two tables: Person and Patient. These tables had a one-to-one relationship. Person held demographic details and Patient held clinical-specific information. Whether this is the best database design is not important, but you can probably see that when you want to work with a "patient," it is tedious to have to work with two separate objects. EF allows you to create an object that is spread across two tables, allowing you to write more intuitive code, such as the following:

Patient.Firstname
Patient.BloodType

8.2.2. Code Generation

A great advantage of using an ORM solution is that it provides basic CRUD (created, read, update, delete) functionality, saving you from having to write this part. As code is automatically generated, the potential for errors is also reduced. Using an ORM can also make it easier to adhere to naming conventions, as classes and methods are automatically generated.

It is worth noting that by utilizing an ORM framework for data access, you are introducing additional overhead to data access, and that for high performance applications, you may be better off working with the database directly. Generally, however, the performance implications will probably be pretty minimal and outweighed by the other advantages an ORM solution can bring.

8.2.3. Support for Different Databases

EF provides support for a number of different databases in addition to SQL Server, such as Oracle, MySQL, SQLAnywhere, Synergex's Synergy (added recently), and a few more.

EF contains its own query language and mechanisms that provide you with a consistent query mechanism that can be used across many different data sources. EF doesn't care whether your database uses T-SQL or PL/SQL—querying is the same.

8.2.4. Design-Time Support

EF has excellent design-time support that developers will learn quickly. Yes, it was a bit ropey in the original version, but this is much improved in VS2010. I don't think the majority of ORM solutions provide this level of GUI functionality, so this is definitely one of EF's strengths.

8.2.5. Utilizing LINQ

L2E allows you to construct some very complex queries using the .NET Framework that would not be possible with standard SQL (we will look at L2E shortly).

8.2.6. N-Tier Application Development

EF has a number of features (particularly in the latest release), such as support for POCOs (plain-old CLR objects) (e.g., .NET classes!) and self-tracking entity templates, that make it a great solution for the development of n-tier applications.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.9.124