Welcome Guest Search | Active Topics | Log In | Register

Strongly typed .Include() in Entity Framework Options
js_vistadb
#1 Posted : Wednesday, June 17, 2009 12:16:16 PM
Rank: VistaDB Staff

Groups: Administration, VistaDB Staff

Joined: 8/13/2006
Posts: 3,402
Points: 3,991
Location: Mount Dora, Florida
I came across this blog post about a strongly typed include for EF.

That has been a sore point for me with Entity Framework.

If you have an object (Orders) and you always want to load all the children (OrderDetails) you have to do a really ugly .Include("OrderDetails"smile string! What happens if you misspell it? You get a lovely RUNTIME exception. I find it hard to believe MS missed this one. I hope it is fixed in the next EF release.

I have not tried the code in the post to see if it works. But it would be nice.
Jason Short

Ron Grove
#2 Posted : Tuesday, June 23, 2009 1:30:51 AM
Rank: Member

Groups: Member

Joined: 10/5/2007
Posts: 12
Points: 27
Location: Beaverton, OR
These strings are also a problem during refactoring. I've run into it with another vendors OPF believe it or not. I suppose if I didn't refactor so much it wouldn't be a problem. But I always seem to come up with "better" names as I go so I pretty much dropped it. A refactoring tool is a lot less productive when you still have to run a find in all files command after the refactoring to figure out where all those loose strings you missed are...

-Ron
davidmccallum
#3 Posted : Tuesday, June 23, 2009 6:47:34 AM
Rank: Team VistaDB

Groups: Member, Team VistaDB

Joined: 8/13/2006
Posts: 523
Points: 2,313
Location: Edinburgh, Scotland
One word CONSTANTS
js_vistadb
#4 Posted : Tuesday, June 23, 2009 11:02:06 AM
Rank: VistaDB Staff

Groups: Administration, VistaDB Staff

Joined: 8/13/2006
Posts: 3,402
Points: 3,991
Location: Mount Dora, Florida
Yea, why didn't the EF code generator put constants in the namespace. That would let you do an include with .Table.Includes( Othertable.Name ) and it would always be the correct string. I guess you could do it yourself with extension methods.

Jason Short

Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAFPro Theme Created by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.3 | YAF © 2003-2009, Yet Another Forum.NET
This page was generated in 0.058 seconds.