EFExtensions , released on CodeGallery earlier this week by EF team member, Colin Meek, has a lot of brainy goo in it. So far I’ve looked at the pieces that Colin has explained in his first post (first post ever) about the Extensions. While most of the extensions in the first part of his post are replicating what Object Services does, the last chunk displays the real benefit of having them at hand.
EF Function Imports can handle READ stored procedures that return existing entity sets. At first I was looking at the extensions to see if they can return random objects, but I haven’t seen that yet however there’s a lot to look at still. (I’m picturing a generic method that reads the columns and creates an anonymous type on the fly rather than having to go through all of the mucking with the model to make this work. Of course, this is for read-only results.)
What Colin’s post shows, however is sprocs that return shaped results. A standard function import can’t do this…it needs to map to a single entity type.
So by combining a few of his extensions, he is able to extract the different types from the shaped results and mimic the object materialization that happens under the covers in expected scenarios. Additionally, he is able to add these entities manually into the change tracker.
It’s pretty sweet and what’s funny to me is that I was trying to do something very similar to this on the same day that Colin released the extensions. I had seen them pop into Code Gallery, made a mental note and a quick blog post without digging into them yet, then a few hours later asked on the forums, “Any way to grab sets of (unrelated) entities in one database call? “. Small world, eh? Now that I have a better understanding of some of the extensions, I will have to go back and see if this does the trick.
Sign up for my newsletter so you don't miss my conference & Pluralsight course announcements!