I tried to make the switch... but Linq-to-Entities is just so much more work!
Recently I tried, I really tried to like L2E, but I just can't do it!
It adds layer upon layers of extra crap I have to do over L2S while offering little to no improvements over the soon to be deprecated ORM.
I am officially sticking with L2S until they get L2E better developed.
Now I am hardly the first person to write about this, but I feel my concrete examples are somewhat helpful when trying to decide.
Now I have read a bunch of reason of why not to switch, but I stubbornly went along and tried it myself.
I like to dumb down my reasons to simple examples of why I have come to loathe L2E (these are all using the same exact DB):
DataSources
I'll just show you on this one, it may not seem like a lot, but try it for yourself and see how confusing the syntax can get:
Linq-To-Entities
<asp:EntityDataSource ID="edsState" runat="server"
ConnectionString="name=J1Entities"
DefaultContainerName="J1Entities"
EntitySetName="state" Select="it.[state_id], it.[state_name]">
Linq-to-SQL
<asp:LinqDataSource ID="ldsState" runat="server"
ContextTypeName="dbDataContext"
Select="new (state_id, state_name)" TableName="states" />
Now I don't know about you, but the L2S is just easier to understand.
Why the hell do I have to use it.[column_name]? That doesn't make any sense.
Not to mention the GUI may as well not be there if you are trying to use automatic Delete, Update or Insert.
Relations
This one is HUGE!
Let's say you have a Foreign Key relation of state_id that relates to a table states and Primary Key that is also named state_id;
here is how you do that in both frameworks:
Linq-To-Entities
item itm = new item() { item_name = "party" };
itm.state = db.state.First(s => s.state_id = 5));
db.AddToitem(itm);
db.SaveChanges();
Linq-to-SQL
item itm = new item() { item_name = "party", state_id = 5 };
db.items.InsertOnSubmit(itm);
db.SubmitChanges();
Now this is a super abbreviated case, but you can see the huge amount of overhead this can create not to mention programming time.
I made these as succinct as I could not to try to advantage one over the other and the L2E is just burdensome.
Even if I were to make a simple Get() method for state it would still make another call to the DB when I already know the relation integer!!!
What an unnecessary step.
And this extra work increases like crazy on large object with multiple relations.
Updating your Model
Now I can't relaly show this as an example, so I will just try to explain it.
One big pain (I thought) in L2S was the fact that you had to pull your tables back in to your dbml every time you made a change to the DB (I know there are tools for this, but I am talking stock).
L2E had this nifty feature that allowed you to 'refresh from the database' that I thought would actually work.
The problem is, that if you change anything with
any complexity whatsoever, like a
Foreign Key, or even something as simple as changing a data type from
VARCHAR to
INT it seems to completely break your edmx.
And this isn't simple to fix like a dbml, not even close.
You can't drag a table into a edmx, and you can't seem to fix it through the refresh so what do you do?
- Delete your edmx completely
- Go into your web.config and delete the ConnectionString (unless you want duplicates)
- Completely remake your edmx
- Redo any changes in the crappy naming conventions to ALL of your tables that you changed (more on this later)
Wow... all that because I changed a relation? No thank you.
Dragging that table into the dbml doesn't seem so bad now.
Relations Part 2
This one isn't as big of a deal, but it is annoying.
Linq-To-Entities
item itm = db.item.First(i => i.item_id == 12);
itm.stateReference.Load()
string whatState = itm.stateReference.Value.state_name;
Linq-to-SQL
item itm = db.items.First(i => i.item_id == 12);
string whatState = itm.state.state_name;
Just simpler in L2S and you don't have to remember the Load() if you forget, and it's in a lot of code, it can be extremely aggravating wondering why your relation is empty.
Not to mention that reference.value syntax in there... more unnecessary (in my eyes) crap.
Relations Part 3
And this was the straw that broke the camels back...
I was so used to the simplicity and convenience of L2S that this drove me nuts and was the reason I decided to give up.
Relations are used so well with L2S that to show relations in something like a Repeater or GridView is almost trivially easy
Linq-To-Entities
Who knows?!
Linq-to-SQL
<asp:BoundField DataField="item.state.state_name" HeaderText="State Name" SortExpression="item.state.state_name" />
but since L2E requires that wonderful
Load() method, it is now not so easy - to tell you the truth, I never figured it out how to make it work, probably have to call something on the RowDataBound event,
but at this point I figured what is the point?
I am officially resigning from L2E (for now) and going back to L2S... maybe next go-round L2E won't be such a pain?
Isn't new technology supposed to make our lives easier?
Going from L2S to L2E is like 'upgrading' from a blender to a hand-mixer; it will get done, it will just take you longer and be more frustrating.
Hopefully, considering that is the was MS is heading.