Google Search

Google
 

Monday, July 21, 2008

Video: ADO.NET Data Services - Query Interceptors

Presenter:Mike Taulty

ADO.NET Data Services has a facility whereby we can plug-in code to run whenever a query for a particular entity set is executed. In this video, we take a look at how we can write these Query Interceptors.

The following text is a software generated transcript of the video. Click on a minute link to jump to a location within the video


Minute 0

Well and welcomed the short video on a whodunnit data services manager Mike Tolkien I work Microsoft and UK this is one of a number of videos about data services bird prodded V 6 preceding that in the series what I thought that in this particular video is how we can write pieces of code that plug in on the server side in order to execute when somebody queries one of your particular resources or sets of entities depending on what you want to use the terminology professors if somebody comes in queries for customers or orders you can plug a piece of code to get involved in that query and make some decision about what what to do as part of plugging into that such a survey freedom book the server side to intercept a query and hence is very well made to let up into visual studio have a look at how that looks up a sunnier visual studio 2008 and using the same data service with use throughout these figures it s the northern database taken in the form of

Minute 1

An entity framework model and then surfaced up through a development data services though something that we ve done previously is just opening up this SEC filing a browser and then we can execute a query against this to a demand for instance customers are our ski is a good record and then we can get that back from the framework I ve been doing this all the way along so the idea rather query interceptor is that we can write code within service so his service fuss over here that arise from Web data service had instantiated around the classifieds data which froze comes from the entity framework they began to get that all on one line and we can add methods to this bad intercept queries for particular sets of entities so it we do that easily can write a method so much to method and then the return type of this should be of an eye query will type

Minute 2

That you get into the middle of a query to Sundays coming in with a query and you hook into that and you return something that is query of bull such that the query can continue to be composed and will perhaps say that a second so I say I want to hook into the queries of customers so I can return an eye query bore of customers and will have this matter causes like intercept customers it doesn t really matter is what this is going to be given is an eye query will of customers at school at the query may recall that in coming query something like that and then what we might have to do is return something in the first instance is just returning coming query concerns pretty simple to do and then what we need to do here is actually took this method in a couple of ways to say that it is acting as an interceptor so we have and to be called query into sector and it says has a name saying

Minute 3

What kind of query are you trying to intercept what entity sets you trying to intercept because customers notice that you can t put starring there so that s not something you could do and if you could put star in their usual struggle of the bit with these types guess that the breakpoint on that and build code and then let s go back over here and view that SEC filing a browser and let s just set that up as start page but set this up as star projects at present five is if we can get that basis below is the page from immensely vigorous for some sort of customer data may be asking this case he is breakpoint coming in saying we have a query and when unassuming to that right here inside of the debugger we have a query coming in and would you like to intercept it and change it before a query continues on their barren mind that we could have customers

Minute 4

Alfie orders were interception code is still in the middle of that query so we re getting involved the customers level before we get to the orders level in that kind of why were given a query will and we return agreeable cuts with part of must have query in pipeline if you like they so we could you have do anything we like inside of his interception method and now we could choose to look at and security information and bounce the request on exceptions of the night that we don t like the request we can relatively easily filter down so friends and say let s say that if you re in the UK are released if your browser claims that you are in the UK which is a fairly flimsy way of identifying somebody them will only allow you to see the UK customers thought we could do is grab the Web operation context which is something that the BCS provides to us and remembering the data services at

Minute 5

Top of WTF so we can get a hold of the Web operation context of current one look at the request is coming in will can be except language header this is not the only way to get this by the weather are other ways of doing this and we could say and let s just say low calorie or something like that and will say if locale equals at the NTB again a great way to compare the sense we could save it and incoming query equals income enquiry got where we founder and say and see producers see country equals UK something like that switch is applying an additional workforce to the query is if your browser says you re in and Great Britain and then we just add an extra cause onto that insult to those results down for you this is just an arbiter of fingers to show the sort of thing you could do here is to liberate one back in that let s go and rebuild looks at him and to get something

Minute 6

Their average have requested the headers of that majesty that was rebuild and let compressor five inherence if we can get on break point having my browser should be saying I m in the UK selector bypass for again customers last to the orders of Alf Key allows numbers of us were asked to customers and they had known just hit the whole thing to offer this will be true from Ian is true to reply that where cause press five continue on and I know that I filtered list of customers are only the ones that my database currently has in the UK so I yet examine and arbitrating that we just put in the air but you get the idea that this is the place where you can stop talking in on a per entity set basis and starts in the queries are coming in and make modifications to them as the coming in now if you needed to take apart

Minute 7

Clauses from the query of something like that then naturally going to have their understand more about our approval and how expressions are put together in order to do that is still feasible but you have to do a lot more work year old I m doing is adding an additional workforce which makes it quite easy to me to do but you get the idea hopefully as to where it query into Sceptre six what it does for you and what you might got to use it for so did a quick summary on what we ve seen here query interceptors plug in on the server side in order that you can intercept calls to query particular sets of entities so you can say that went on the ask for orders customers or products or suppliers whatever it might be you can look in abuse of drugs going to run at these code is in my mind I was like a piece in a pipeline of assembling a query to get given something that is likely rouble and also returned something that is like wearable

Minute 8

What we did was to filter down the query little bit depending on some dynamic property that came in on the request economic under four kinds of things you might do here I am in your mind including perhaps returning results whatsoever or throwing an exception if you really didn t like the look of the request that was heading in your direction butjust talking on the server side and add extra code and should you want to do that be a bit more dynamic and in what happens on the server side of a so if you want to download the preview and experiment with your own data you need to go to www ASV net you looking threatening call the ASV net 3 5 extension is preview certainly that s how this into practice at the time of recording this video there are a number of technologies in that preview twoofwhichradio net data services and lady of an entity framework so remembered as a preview of a download that and try with your own data sources if you are interested in this technology be an idiot and a data services was previous

Minute 9

Called code named Astoria and is a great blog resource it s as you can sunscreen blocks the amnesty under con Astoria team and if you go there you can keep up to date with what s going on with this particular project and is a bunch of nice resources links on a site as well as you ve want to follow directly with me after the video then feel free to drop me a line using e mail address and screen other than that we have fun and playing with a story egg of a net data services hobbies and the video useful and practical joke with you sometime in the future

Click here to go to original video page

No comments: