ASP.NET 4.0 Dynamic Data and Many to Many Entity Framework Entities

Even though I’m a much bigger fan of distributed apps than using UI bound data binding, it’s still important for me to know how these various tools work – especially since I need to write about them in my updated E.F. book. 😉

I did not play much with Dynamic Data controls in VS2008 and just made a cool discovery in VS2010 Beta 2. This may not even be new, but as I’m sitting 30,000+ feet over the Atlantic ocean, I don’t have access to VS2008 at the moment to check.

I have a database that has a join table between two other tables.

m2mdatabase

Because the join table has only the keys of the tables that it is joining (and no other fields such as “AddedDate”, etc.), the EDM Wizard is able to create a many to many relationship between them and hide the join table. (If there were additional fields in the database table, then there would be a join entity in the model.)

m2mmodel

I just created a new Dynamic Data website using all of the defaults except for one. Rather than automatically using every entity in the model, I selected specific entities to include in the site. Other than this, I have done absolutely no customization.

When I ran the app and opened up the People page, I was surprised to see the names of the individual beers listed in the Beer column.

m2mPerson

But I was even more surprised when I chose to Edit the person and saw how brilliantly the Dynamic Data templates handled the Entity Data Model’s many to many relationship.

m2meditperson

I am going to have to stop turning my nose up at these tools, though I may still have to pinch my nose for Mr. lePieu and his choice of beers. (Better get some Magic Hat onto that list!)

For RAD website development, this is pretty impressive stuff!

  Sign up for my newsletter so you don't miss my conference & Pluralsight course announcements!  

7 thoughts on “ASP.NET 4.0 Dynamic Data and Many to Many Entity Framework Entities

  1. Very cool, how does it compare to the scaffolding abilities of (asp.Net) MVC? If it is even easier it might make a good back end scaffold during development of large projects, even if they are MVC.

    Also Magic Hat rocks! Though I am more fond of our local brews http://www.flyingdogales.com

  2. Adam, ASP.NET MVC 2’s dynamic templated views are based on parts of Dynamic Data. So it’s a different take on the same code. Don’t try to use Dynamic Data in MVC; the parts you need for MVC are already built in to MVC 2.

  3. I thought the question was if MVC templates will handle the *:* as the DD templates did. I’ve got some other stuff to do but plan to test that as well.

  4. Can Dynamic Data in VS2010 Beta 2 implement true Master-Details? E.g., with Northwind as the DB, say if I’m on the Insert page for Products and I’ve fed in values for each of the fields. I then come to Categories or Suppliers dropdown and realize that when I click on those, the relevant items have yet to be fed into Categories or Suppliers. What I’d normally have to do then is to click "Back to Home Page" and insert the needed record into Categories/Suppliers as the case might be. But then, the data I’d already fed in the Products Insert page is now lost! Imagine if I had 100 or so fields, I’d then have to re-feed all of those when I come back to Products Insert page?

  5. This type of functionality (in an even better form, IMHO) has been around in some of the better PHP-based MVC frameworks for several years now. CakePHP, for example.

Leave a Reply to admin Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.