Wednesday, June 24, 2009

Introduction to the Microsoft Entity Framework

As you may have seen on the Advantage Announcements Feed the latest version (9.1.0.9) of the Advantage .NET Data Provider now supports the Microsoft Entity Framework. But, just what is the entity framework?

The Entity Framework (EF) was released as part of Visual Studio 2008 service pack 1. So you have to have the latest VS2008 service pack installed to use the EF. EF provides an Object Relational Mapping (ORM) which allows developers to create objects within their application which represent the relational database. This technique has been available for some time through other products such as nHybernate and eXpress Persistent Objects from Devexpress.

The EF comes with an object modeler which can create a new object model based on an existing database. You can also create objects which do not map directly to a database object. For example if you need to view data from several tables you would normally write a query within your application or create a view in the database. When using the EF you can create a model that represents the data the way you need it for your application which can simplify development.

Below is an example model built from an Advantage Data Dictionary. The database is the one used by the Microsoft Entity Framework quick start guide that we migrated to Advantage.

School Model

As you can see the model includes all of the fields in the tables, called scalar properties, as well as relationships between tables, shown as navigational properties. This interrelation between these objects makes them very useful within your program. For example if you wanted to see the course grades for a student you can do this by creating an ObjectQuery that includes the CourseGrade link within the Person table. With the link established in the ObjectQuery the grades for each student are now part of the Person object and available to your program.

Entities can be accessed using LINQ to Entities or with Entity SQL. These are both very easy ways to access your data through the entities that you have created. These methods are also used to modify the data contained in the underlying tables as well.

I am currently working on some example code and a series of screencasts on using the Entity Framework with Advantage. These should be available over the next few weeks so stay tuned.

2 comments:

Unknown said...

Got any guidance for us nHibernate folks? Thanks!

Anonymous said...

NHibernate support would be nice.