Mike Taulty's Blog
Bits and Bytes from Microsoft UK
Entity Framework - Entity Provider Level. Simple Querying Application (eSQL PlayPen)

Blogs

Mike Taulty's Blog

Elsewhere

Wanting to play with eSQL a little made me want to find a generic way of executing a query and viewing the results so I knocked together a Windows Forms application that would do that. Note, this was only really the results of a few minutes of playing so don't assume it's correct but, perhaps, you might want something similar and if you find that it's broken you can modify the source to make it work :-)

There may well be a sample up on CodePlex that does a similar thing to this so you should check but, at the time of writing, those samples aren't updated so I cooked up my own app.

It looks like this but, first, it's time for a big note.

Big Note - this client is not perfect, if you're in any doubt about your result-sets then verify them elsewhere as I know that the way I'm handling the results of certain queries here isn't 100% correct but it does provide a simple "play-pen" to type a few queries into.

image

Once you've got your metadata folder, your provider name and your connection string set up you can bang in a query and hit execute and I'm just using the old fashioned DataGrid to try and display multiple DataTables within a DataSet hierarchically (because, AFAIK, you can't do that with the more modern DataGridView).

The code that's likely to break in all this is the code that tries to take an EntityDataReader and get the results into a DataSet - I hacked this together fairly quickly so don't be too surprised if you get breakages but, at least, it's a start. Someone will probably mail me and say "Hey, you do realise that you can just bind an EntityDataReader to some fancy UI widget without any code, don't you?" but I didn't know of another way to do this.

So, if we run a query like the one above, we get;

image

and if we run something that returns a structured type then what I do is to to create a 2nd table within the DataSet and fake up a relationship between the two things. So, it'd look like this;

image

where that column cKey is something that I just faked up to represent the fact that the value is a "complex type" which I've shoved off into another table and you navigate it like so;

image

and that then gives you;

image

(Hey, sorry about the names used here - they're terrible :-().

And we could have a more complex query such as;

image

 and then you've got two complex types to chase down. Expanding out orders for one of those customers;

image

and that gives the orders (in terms of EntityKeys anyway) for ALFKI;

image

Now, I'm a bit suspicious of how my code works if I then DEREF this particular relationship - it feels like I end up with a level in the hierarchy that I wasn't expecting but that might either be my dodgy code or it might be that I don't full understand the shape of the data that comes back yet.

I've uploaded the source here so that you can use it, copy it and (hopefully) improve it to the point where it works properly :-)


Posted Mon, Aug 27 2007 3:40 PM by mtaulty

Comments

Mike Taulty's Blog wrote ADO.NET Entity Framework - Bringing Together A Few Previous Posts
on Wed, Aug 29 2007 5:37 PM
This is just a convenience - links to the posts that I've made so far around beta 2 of the ADO.NET Entity...
Entity Framework from Mike Taulty « vincenthome’s Software Development wrote Entity Framework from Mike Taulty « vincenthome’s Software Development
on Fri, Sep 7 2007 7:24 AM