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.
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;
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;
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;
and that then gives you;
(Hey, sorry about the names used here - they're terrible :-().
And we could have a more complex query such as;
and then you've got two complex types to chase down. Expanding out orders for one of those customers;
and that gives the orders (in terms of EntityKeys anyway) for ALFKI;
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