I was tasked by my manager to implement NHibernate for our next project. I've heard a lot about it and was looking forward to learning NHibernate to meet requirements. Seemed like most of the learning curve would be spent in XML configuration files; in my research I stumbled upon fluent-nhibernate which is the route I would have taken had I not run into Scott Guthries comprehensive blog on .NET 3.5 SP1 (beta) - excerpt included at the end of this blog.
Since .NET 3.5 SP1 was now released it fell into the realm of the only rule my manager has for me - it must be released, no CTP or beta. Having worked with the Web Service Software Factory (WCF) Modeling edition it was an easy decision regarding whether to use the Entity Framework (EF) modeling tool over NHibernate. I still plan to spend time with the source for fluent-nhibernate because it does some pretty impressive things that makes XML configuration go way but EF is what we'll be using.
The process was so simple, and quick, it was impressive. From my DAL project I right clicked and selected Add, New Item and selected "ADO.NET Entity Data Model". From there I used the easy to follow setup wizard and within a few minutes had my EF container containing all of my database objects presented nicely in a Class Diagram. I compiled and everything looked great.
I then added my second EF container and the process went just as quick/easy until I went to compile. I had over 90 errors mostly reporting that xxxx.dtproperties already contains a definition for 'xx'. Further investigation revealed that the format used is <AppNamespace>.<TableName> and it just so happened that we had duplicate table names (and fields) in the two separate databases.
Ideally <AppNamespace>.<DatabaseName>.<TableName> would have been nice but the solution will lend itself to a better design; each Database container will be in it's own DAL project along with it's unit test. If however you did need/want to keep your databases in one project you can manually update the namespace after code generation to include the database name.
An excerpt from Scott's blog on the .NET 3.5 SP1 follows:
ADO.NET Entity Framework and LINQ to Entities:
.NET 3.5 SP1 includes the new ADO.NET Entity Framework, which allows developers to define a higher-level Entity Data Model over their relational data, and then program in terms of this model. Concepts like inheritance, complex types and relationships (including M:M support) can be modeled using it. VS 2008 SP1 now includes built-in designer support to help with this modeling:
The ADO.NET Entity Framework and the VS 2008 Entity Framework Designer both support a pluggable provider model that allows them to be used with any database (including Oracle, DB2, MySql, PostgreSQL, SQLite, VistaDB, Informix, Sybase, and others).
Developers can then use LINQ and LINQ to Entities to query, manipulate, and update these entity objects.
Tags: entity framework