Entity Framework – Disappointment.

17 בנובמבר 2008

For some time I am consulting one of my customers with the creation of WPF application which uses a Sql Server Compact edition DB.

We quickly used Linq to SQL as our DAL and created our data model (using SqlMetal as so far even after SP1 no IDE support for SqlCE, drop me a comment if you don’t know how to use it).

As with everything in life, Linq to SQL has it’s weaknesses but to tell the truth it just works. I’ve been able to put up a full working POC consisting of Composite application guidance and everything in just a few hours work.

Last week I’ve returned back after a short vacation, PDC and some nice work at Redmond.

One of the new things I found out after getting back is that there is a possibly new requirement, a need to work against DB2.

Thinking about the future in this project brought me to several conclusions:

  1. We would like to have one DAL.
  2. We would like to be able to work against SQL Server, SQL server CE and DB2
  3. We would like to be able to model our objects from those sources.

As you might suspect, Entity framework should be a good investment to obtain those conclusions written above. It should now support my development against SQLCE and when the time is right (assuming a provider for DB2 will be shipped) we will be ready for it.

So I started migrating our App to EF.

First Issue:

Linq to SQL:

When you would like to retrieve elements and their associated elements as well in one query, you would have to register it using DataLoadOptions object.

it is very convenient one line of code and setting it inside the DataContext factory and you no longer need to get bothered with it again. It just work.

Entity Framework:

The EF equivalent is using .Include() method with your query. Instead of supplying lambda expression which you got intellisense, this time you need to supply it with a string; the name of the table. This is error prone as hell, do I need to mention table name changes or just honest misspelling?

More cumbersome than that you need to add it to every query you run.

Got an arch object with a lot of associated entities, tough luck, Include got only one parameter so you need to chain them.

Include(“A”).Include(“B”)….Include(“Z”)

Again, for every query!

Second issue:

Linq to SQL:

Lucky for us the data of the app is readonly. We don’t need our DAL to keep track of changes, because there will be none.

So naturally we are using[DataContext].ObjectTrackingEnabled = false.

Entity Framework:

Unfortunately the EF corresponding object (ObjectContext)  doesn’t include such an easy option.

You need to manually check every table for it’s MergeOption and assign it to MergeOption.NoTracking.

I repeat for every table, if you have +100 tables, be prepared for a nice copy & paste finger exercise, who said developers only sit on our buts and do no physical exercises.

Third issue:

One of the key advantages of EF is the ability to model the entities differently than the db. You want to add an association using the designer. I was attacked with mind boggling errors such as :

Error    2    Error 3021: Problem in Mapping Fragment starting at line 1406: Each of the following columns in table XYZ_Product_CHILDTABLE is mapped to multiple conceptual side properties:
XYZ_Product_CHILDTABLE.AAAAID is mapped to <XYZ_Product_XYZ_Product_CHILDTABLE .XYZ_Product_CHILDTABLE .AAAAID , XYZ_Product_GRAPHICProductXYZ_Product_CHILDTABLE .XYZ_Product_GRAPHICProduct.AAAAID _ID>
XYZ_Product_CHILDTABLE.SuperProductID is mapped to <XYZ_Product_GRAPHICProductXYZ_Product_CHILDTABLE.XYZ_Product_CHILDTABLE.SuperProductID, XYZ_Product_GRAPHAlProductXYZ_Product_CHILDTABLE.XYZ_Product_GRAPHICProduct.SuperProductID>

Rough edges ah?

Fourth issue:

The last issue of many I am going to publish here is that a innocent looking query condition such as : Name == “Margol” raises this issue:

The ntext and image data types cannot be used in WHERE, HAVING, GROUP BY, ON, or IN clauses, except when these data types are used with the LIKE or IS NULL predicates.

Apparently there is a bug and somebody along the way thinks that my honest nvarchar Name column of mine is NText, so the == is not valid against it.

Reading this MSDN forum thread, will let us know that a solution has been  found and should be released in the near future, joy.

Well for me it was enough, I’m not to wait for it, I am back to Linq to SQL, and I don’t care of what the guys at ADO.net team are thinking.

See you next version.

Ariel

Add comment
facebook linkedin twitter email

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

6 comments

  1. Tomer17 בנובמבר 2008 ב 14:55

    I liked your approach, going back to Linq to SQL. Unfortunately you still have the DB2 problem… 🙂

    Btw, I think it’s very confusing to have two ORM kind technologies under the same roof. So it’s about time to merge both teams together. I’m sure that they will do better.

    Cheers

    Reply
  2. David18 בנובמבר 2008 ב 1:44

    Yeah, I remember those annoying "Problem in Mapping Fragment" errors, drove me crazy.

    I have yet to find a decent DAL that covers all of my needs.

    Reply
  3. Frans Bouma20 בנובמבר 2008 ב 3:46

    You know, there are other O/R mapper frameworks out there who don't have these silly restrictions _and_ support DB2 🙂

    disclaimer: I'm the lead developer of one of them: llblgen pro

    Reply
  4. ToratordDrale25 בפברואר 2011 ב 20:58

    ruler102|I cried for ages when Snape died and then even more when I found out he lovedп»ї Lily.
    http://canadianmedstore.in/?p=116

    thplousaqq

    Reply
  5. ToratordDrale26 בפברואר 2011 ב 10:15

    alwayspureblood|its deliberately bad, because when we did here in your car which is what we re repeatingп»ї it off of, we had a terrible accent 😛 we re not that bad anymore 😛 x~Cissa~x
    http://generic-stock.com/?p=352

    thplousaqq

    Reply
  6. Everett7 במאי 2012 ב 23:58

    This is my first time go to see at here and i am in fact happy to read all
    at one place.

    Reply