www.allpaul.com

I needed somewhere to put all this stuff
Welcome to www.allpaul.com Sign in | Help
in Search

Programming

Entity Framework Designer Problems (VS-SP1 Beta release)

I have been developing a site using the latest release of the Entity Framework (EF).  The EF is great because it allows me to create business objects that are not directly related to database tables without too much code.  These new objects can be completely different in structure from the relational database that persists them.  For example...I have a Company object that has various attributes like Name, Phone, Fax, Web site and Addresses.  That Addresses is a collection of Address objects from a different database table.  But, I needn't worry about that once I design how I want to present my objects in the Entity Model Designer (More on that in a minute).  Back to that address thing. 

The Company - Address relationship is more complex than CompanyID being a field in the Address table.  Instead, because Companies can share an Address (two companies are at the same location or have the same billing address and when it is updated for one company it will automatically update for the other) there is actually a many-to-many relationship here with a joining table in the database.  That relationship looks like this:

Company->CompanyID, Name, ...

Address->AddressID, Street1, Street2, City, ...

CompanyAddress->CompanyID, AddressID

The one of the coolest things about the EF is once I set up that relationship in the designer (it does most of the work for you really), I can use my objects in a more traditional Conceptual and not Relational way.

So, I can load my Company object and its Address objects using Linq  (overly simplified in this example)

        
        Company c = (from comp in context.Companies select comp).First();

        c.Addresses.Load();

        foreach (Address a in c.Addresses)
            Console.WriteLine(a.Street1);

Cool! But, I have had some troubles with the designer that I believe are just due to its infancy as a product.

  1. The designer creates a .edmx file that stores all of the relations, renamings and reorganization of your database - conceptual model structure. It also creates a ModelName.designer.cs file that includes the generated classes for your new conceptual objects.  This .designer.cs file is created automatically when you build (or save, I think) the .edmx file.  However, on three occasions in two weeks this linking between the files has been lost.  I think it has to do with me restoring the files from backups or moving the directory where the .edmx file lives.  I plan to troubleshoot it more next time it happens.
  2. If you delete a conceptual object that is generated from a database table, there is no easy way to regenerate that class.  I would think right-clicking on the table name in the Model Browser would have some functionality like that, but it only allows an "Update from database" that doesn't recreate the deleted object (and I think that is right because if it did and you really wanted it deleted, you'd be pissed every time it came back).
  3. If you forget to add a relation to your database before generating your Model, go back and add the relationship and then update from database to refresh the Model with the new information, it often becomes difficult to get the table mapping correct.

I think the tool is great in 80% of the scenarios I've thrown at it, but it needs a bit more work.  And, the development team should put together a Webcast to demonstrate how to use the designer for more difficult scenarios.  The only ones covered so far are very simple.

 

Only published comments... Jun 27 2008, 11:18 AM by paully21
Filed under:

Leave a Comment

(required) 
(optional)
(required) 
Submit

About paully21

 

Powered by Community Server (Non-Commercial Edition), by Telligent Systems