About Data Driven Websites and Object Relation Modeling

I’ve reinstalled my machine of last night with Windows 7. I’m very happy with this new platform! Thank you Microsoft. One of the final reasons to start yesterday was that my database integration in Visual Studio was broken. Of course there where many more reasons, but that was the issue which made me do it yesterday evening.

So far so good. This morning I started of with a clean and very fast machine. Visual Studio 2008 was ready to roll. I’ve installed the Developer Edition of VSTS yesterday eve.

Today I decided to spent a little bit of time on getting the Entity Framework to work for a small, highly data-driven portal I’ve to develop. One of the issues with the portal is that it should be ready by yesterday. Not so much pressure, but I wanted to be highly productive. Unfortunately I’m highly disappointed.

While we all still claim that simplistic data driven websites should be online in a couple of hours, the truth is the opposite. I’ve got an app where you’ve got users. Users can be in a WorkGroup and some of those these users are leaders of the group. In objects:

  • User.WorkGroups –> List<WorkGroup>
  • WorkGroup.Users –> List<User> –> All users associated, incl leaders.
  • WorkGroup.Leaders –> List<User> –> All leaders

In the database you’ll store this as 3 tables: User, WorkGroup and an AssociationTable with a property ‘IsLeader’ (bit).

The database design was easily made, as I told you before, I decided to use the Entity Framework. But somehow I was absolutely unable to get this to work. I could get the User <-> WorkGroup(many to many relation) to work, but the Leader-relation couldn’t be made without modifying the generated code(or maybe the XML?). 

I’m sure one of you guys will give me the solution how to get this to work. And once again absolutely sure that this is not impossible. But I’m in general wondering why I couldn’t figure this out during the 2 hour R&D I’ve spent on it. The designer doesn’t seem to support something like that. Or it is hidden, somewhere. I’m not sure if this is just a limitation of the Entity Framework or of many O/R mappers.

I do know I generally dislike my whole process. I’ve been switching over and over between the different designers for my entities and database. This makes me wondering. What if this is your daily task? Getting a model designed by business users(interpretation I), normalize this(interpretation II), fit this into an object design(interpretation III) and maybe redo some of these part during one of the stages.

Let’s look from a perspective of a developer. I do not care about the database. It should just be stored. I care about the way I can access the data, so I want to control the types in my entities. My illusion: create a model(we’ve got a language for that: UML). Hit a button, and code + database should be ready.

Optimizations for storage and in the data access code should be done by the generation. The computer is way smarter when it comes to optimizing, it can calc all data access roads and ask if I want to flag more often used data. When I want to create a specific method(for example: GetById) I can define it in OCL.

The solution seems to be so obvious. Why can’t I find such a tool? I can find database generation tools, I can find O/R mappers. I can even find frameworks which should be O/R mappers(isn’t the Entity Framework the framework to be?). But none of these support my vision.

What can I do know? I can use a CMS to store my relational data. All my relational data, maybe thousands of records. I’ve to find a way how to store it internally as CMS’s use all kind of structures, but never a relational one.

I’ll end up in this project using an heavily modified Sitecore installation with lots of custom code to get around the limitations(I’m able to write that quickly as you can imagine). But hopefully you’ve seen my point. I gives me a huge headache in this age of data generation, web service generation for out scaling, advanced cache structures, cloud computing, etc.

Do you got a solution in mind for me?

Note: This is a post written out of my experience as an architect in many projects. I’m involved in general in Sitecore projects, but rarely I’ve got the opportunity to ‘work’ a little outside of this boxed environment. Often these high level problems arise as well in project where Sitecore is involved. I won’t blame a vendor, but I’m wondering why we smart guys are not able to solve issues like productivity without doing concessions on the business requirements.

LINQ is all about being smart

The competent programmer is fully aware of the limited size of his own skull. He therefore approaches his task with full humility, and avoids clever tricks like the plague.

I wanted to be smart. I tried to use LINQ to XML for parsing an Atom feed. Here’s what I’ve got to read a link:

var urlElement = item.Elements(xmlns + "link")
                                .Where(link.Attribute("rel").Value == "alternate")
                                .Select(link => link.Attribute("href").Value)
                                .First();

Do you see the issues? 3 Nullpointers:

  1. Attribute “rel” in my Where
  2. Attribute “href” in my Select
  3. First() –> What if I have nothing to get the first of?

Once again this underlines what Edsger W. Dijkstra said in the quote written above. You try to be smart by using the latest stuff, coolest tools, etc. But the limitations are never described, you’ll only experience them while debugging.

Another lesson learned.

Small update: Those who are using Resharper will get notified about the first 2 nullpointers, but not about the third. On the other hand, solving that in the where clause doesn’t fix the value analysis (seems to be hard in lambda’s).