Hydrating a DataTable from an EntityDataReader – Part 2

See yesterday’s post for some context… So we can’t rely on EntityDataReader.GetSchemaTable() and a DataAdapter to do the filling of our DataTable for us. We have to do it ourselves. As with any problem the first step is to define the steps: Get a DataTable with a shape that matches the EntityDataReader. Enumerate the reader…

1

Hydrating a DataTable from an EntityDataReader – part 1

Okay so about 5 posts back I promised: “…At this point we have an enumeration of all EntitySets available. In the next post I explain how we can use that…” Well better late than never… If you remember last time I showed you this piece of code: MetadataWorkspace workspace = conn.GetMetadataWorkspace(); var sets = from…

3

Dude where is my query going to run?

One of the key decisions with LINQ to Entities (L2E) is that all predicates in an L2E expression must be converted into store expressions, so that the store does all the heavy lifting. This means for example if you try the following: var matches = from e in ctx.Employees               where IsTopPerformer(e) && e.FirstName.StartsWith(“C”)              …

1

T CastByExample<T>(object o, T example)

So earlier today I was lamenting that an anonymous type can’t be shared between functions with Wes Dyer, when he said “Well actually they can…” Cue me learning something cool. The first step is to create a seemingly innocent method: public static T CastByExample<T>(this object o, T example) {     return (T) o; } Seems…

15

EntityConnectionStringBuilder

In my last Metadata post I suggested using a string template to create an EntityConnection connection string. Well it turns out there is a better way… Enter the EntityConnectionStringBuilder class. The only thing it is missing is the ability to specify the location of each of the metadata files (CSDL, SSDL and MSL) separately, you…

1

Compiled Queries and the EntityFramework

For a while LINQ to SQL has had compiled Queries… and now in Beta3 of the Entity Framework, due out soon, we have them too. The idea behind compiled queries is that you don’t want to re-process the same LINQ expression every time it is encountered. Instead you want to pre-compile the LINQ expression, so…

2

CommandBehavior.SequentialAccess

So why does this: EntityDataReader reader  = command.ExecuteReader(); Throw an exception? Well it is to-do with correctness and setting expectations. First things first, this is what you should do: EntityDataReader reader = command.ExecuteReader(CommandBehavior.SequentialAccess); But why? What this does is explicitly open the reader the only way we currently support: sequentially. Which begs two questions: What does opening…

4

Using a random model at runtime

In my last post I hinted that using the Entity Frameworks Value layer and Metadata allows you to work against any Entity Data Model in a loosely coupled way. Let’s see how… So let’s imagine you are working against the Value layer. With code something like this: using (EntityConnection conn = new EntityConnection(conn_str)) { conn.Open();…

4

Metadata, Objects and Values

One of the things I am doing at the moment is writing a bunch of Entity Framework code with one common theme, leveraging metadata. In the spirit of transparency here is what I have learnt (just this, nothing else at all…) When working with the entity framework from the developer perspective there are 3 layers:…

2

Sharepoint tricks

So Alex Henderson, who took over running the Auckland Architecture chats from me, has been busy recently compiling a wiki full of SharePoint Hacks. Hopefully this will grow overtime, but even as it is it is a useful resource. Asad, who has been my peer mentor introducing me to the ways of Microsoft, and I…

1