Archive

Archive for the ‘Ado.Net’ Category

Entity Framework => Entity Base Class Library

November 23rd, 2008 stiiifff 5 comments

A few days ago the Entity Framework Team released a proposed solution for N-Tiers change tracking on entities … or should I call it a no-solution?

Basically, they will provide a low-level API that will allow YOU to do change-tracking the way YOU prefer.

5 months ago, I was writing a big NO to the Vote of no confidence. Well, now that I had to use Entity Framework on a real project, I must say that I was wrong. I really tried my best using it, thinking that it would be a safe bet for future evolution … and I know what I'm talking about when using ORMs, I'm a very advanced user of NHibernate (multi-tenancy, dynamic filters, dynamic mappings, partial domain models anyone?) … but my only conclusion to the Entity Framework is : WTF are they doing ?! Is that all you could come up with after months of research, brainstormings, experts meetings ?!

If someone give me a set of classes that doesn't bring a A to Z solution to a problem, sorry but I don't call it a Framework … I call it a Base Class Library. I've been vey supportive to the Entity Framework Team (I gave design feedback through multiple channels) but now I think I'm done. And it seems that others have the same feeling : Frans Bouma, author of the LLBGenPro ORM tool, goes in that direction too with its answer to the original post, and a full post on his blog, wich I both totally agree with.

I mean, come on, all those abstractions and discussions are very interesting but after some extensive periods of time trying to make this thing become useable, you have to ask yourself some serious questions. Even the now defunct Linq2Sql is more pleasant & easier to use.

Anyway, I will now go back using something that is customizable, extensible, that allow me to work the way I want (Domain-Driven Design) and most importantly that actually works : NHibernate. I recently discovered that it's moving full speed to version 2.1 with great new features such as Entity Modes : see here and there to know what I'm talking about. Also, a great workshop video on advanced use cases of NHibernate by Ayende.

Update: Ayende's reaction to the Entity Framework Team's design post.

Ado.Net Entity Framework – Vote of no confidence – NO !

June 24th, 2008 stiiifff No comments

Just stumbled on the new soap opera of summer 2008: the so-called Ado.Net Entity Framework Vote of No Confidence (that I will nicely abbreviate ANEFVONC). Come on, we have Euro 2008 Cup, the Olympic Games in China … isn't that enough ? ;)

The open letter describes the main problems that, following the Alt.Net community, currently prevent the Entity Framework from being a great DDD Tool:

  • INORDINATE FOCUS THE DATA ASPECT OF ENTITIES LEADS TO DEGRADED ENTITY ARCHITECTURES: Yes, EF is currently mainly about data access … let's hope it will evolve and introduce more & more 'Entity services'. Concerning Business Rules, is there a standard way of expressing Business Rules that EF could include ? Not sure about that but anyway I don't believe that EF currently prevents you to define your BR … because in a system with numerous & complex BR, your BR logic wouldn't be coded right inside your Entities. ;)
  • EXCESS CODE NEEDED TO DEAL WITH LACK OF LAZY LOADING: I remember EntitySet<T> has Lazy Loading built-in … but yeah, then you're not 100% PI compliant anymore. And no, I don't need Lazy Loading to keep my business logic free of Data Access concerns. I can use specific Repositories that will contain custom Linq queries if my base Linq-generic Repository is not enough. Lazy Loading is very appeling at first, but frankly, is only applicable to simple cases. 'Transparent data access' is a myth … you need to express a query in some form. Defining relations in order to benefit from Lazy Loading is a very simplistic view of the task of Querying on a Domain Model.
  • SHARED, CANONICAL MODEL CONTRADICTS SOFTWARE BEST PRACTICES: Haven't tested EF on that point … but indeed, support for Partial Models (see here, and here) is needed for complex Domain Models (especially when split in many Modules).
  • LACK OF PERSISTENCE IGNORANCE CAUSES BUSINESS LOGIC TO BE HARDER TO
    READ, WRITE, AND MODIFY, CAUSING DEVELOPMENT AND MAINTENANCE COSTS TO
    INCREASE AT AN EXAGGERATED RATE
    : Last time I checked, the EF Team had written a post on its blog to express its commitment to making EF as close to PI as possible … did they changed their mind ? Or is the Alt.Net community not patient enough? lol :)
  • EXCESSIVE MERGE CONFLICTS WITH SOURCE CONTROL IN TEAM ENVIRONMENTS: Well, let's hope it can be fixed.

Although, I think I understand most of the concerns expressed in the letter, I still feel that it focus too much on the data access part of Domain Driven Design … and DDD is so much more than that, right? IMHO, here are some key problems that must be adressed for DDD to hit mainstream:

  • Bridge the gap between DDD & MDD: I want to do DDD, but I don't want to know 100 patterns and tricks and tips in order to work efficiently … Gotta focus on defining the Ubiquitous Language right ? ;) What we need is a Meta-Model for DDD that allow us to create our Domain Models more easily than with Code, Unit Tests, Refactoring … I want to work at a higher level of abstraction, please. Give me DDD domain-specific languages !!! (a textual one for purists and a graphical one for realists, both being SCM-compliants).
  • DDD Best Practices Validation Rules: Create Generic DDD-specific rules that can be verified on the Domain Model created using the DDD DSL. Allow to define Domain Model-specific rules (= Business Rules) directly at the Model level, using a Business Rules DSL.
  • ORM-free DDD Code Generation: Well, if my first wish is realized (DDD DSL), then generate the code for me based on what I have described using the DSL. One way code generation would be fine (if they are enough extension points otherwise, we are back to square one with open letters and blah blah). Bi-Directional DSL would be great, but much much harder. Also, make the code generator pluggable … so that, any ORM-specific artefacts can be generated (keep the core DDD DSL free of any ORM-specifics). Also, generate Business Rules code.
  • Relationship as first-class elements of the language: let's get rid of those horrible Add / Remove methods hiding the fact that we are still not able to manage bi-directional relationships correctly & consistently. Make the concept of relationship an integral part of the language (Linq 2.0 ?). A great article on the subject (in french, sorry).

Other interesting (old !) posts that also shed light on the fact that DDD still has a long way to go: here and there.

Personnally, I think that EF is the first building block for more DDD goodness to come … so, give feedback, but be patient. I believe an annoucement like this one can only bring good things. Like NHibernate, Rome wasn't built in just one day.

Or did I miss something ? :)

Reminder: Never a sign a paper just because a lot of other people did it before you. ;)

Internals are evil … another example in Sync Services for ADO.NET ?

April 23rd, 2008 stiiifff 2 comments

I've been testing the Sync Services for Ado.Net lately, and I came accross a problem when using an Oracle as back-end database. Well, we all know that Microsoft always offer a good default implementation for SqlServer for all their tools & frameworks, and additionnaly, comes with a Provider model so that “you're welcome to develop your own provider implementation“.

Still, I was puzzled to find out that the SqlSyncAdapterBuilder class that allows you to quickly create SyncAdapter objects (contains information about the server-side tables to be synchronized) was using a DbSyncAdapterBuilder class that is marked as internal. Having a further look at this class shows that all the types used are database-independent (e.g. DbCommand, DbParameter) and that its responsibility, as its name implies it, is to contain the database-independent logic needed to build database-specific SyncAdapter objects.

Obviously, there are 2 reasons for Microsoft to mark such a class as internal:

  • Strategic choice: Make it less simple to use Sync Services with other databases than SqlServer, thus pushing the adoption of their own RDBMS. Don't get me wrong, you can still use Sync Services without using a SyncAdapterBuilder, but it requires much more coding.
  • Deadline problem: The main implementation of SyncAdapterBuilder is for SqlServer, it was fully tested and is thus fully supported. However, Microsoft cannot guarantee that the DbSyncAdapterBuilder is fully database-independent and that it would allow to build correct implementations for other RDBMS. As a consequence, they prefer to mark it internal. Well, I guess it would not be acceptable for Microsoft to provide such a class with a disclaimer on top of it 'Use at your own risk. Not fully tested'. ;)

Whatever the reason is, now I'm wondering if I should implement an OracleSyncAdapterBuilder or create a small DSL (the LocalDatabaseCache dialog in Visual Studio 2008 is built on top of the DSL Tools by the way) that allow to configure the synchronisation & generate the code for it (without using a SyncAdapterBuilder).

Anyway, let's hope that we'll soon see a shiny 'Sync Services for Entity Framework'.

Update: Turns out I was more or less right about the second option for marking DbSyncAdapterBuilder internal … while SqlSyncAdapterBuilder forwards some property & method calls to a private DbSyncAdapterBuilder object, some of the static methods of the DbSyncAdapterBuilder class are calling back to internal static methods of SqlSyncAdapterBuilder !!! Don't ask me to name this (anti-)pattern … let's just consider the cause was a deadline problem, and the developers had to reduce the initial scope of the framework due to lack of time.

Tip: Forget about implementing an OracleSyncAdapterBuilder class, prefer the code-generation route instead (combined with a DSL for configuration of the synchronized tables for example).

Categories: Ado.Net, DSL Tags: ,

Occasionally Connected Applications using Sync Services for ADO.NET

April 21st, 2008 stiiifff No comments

Today, I discovered the Sync services for ADO.NET … exactly what I needed for a project. Not many people know that it's part of the RTM version of Visual Studio 2008 (ever tried to add that “Local Database Cache” to your Windows Forms project ?). Basically, it helps you synchronizing data between a client & a server data store. It is particularly useful in so-called “occasionally connected applications“, which usually embed a lightweight database to have a local cache of data.

Here are a few links to get started:

Update: This site has it all.

Hope it helps … ;)