locked
How Data service work and 2 interceptor on one object? RRS feed

  • Question

  • Hi All,

    I am very new to Data services and i found it very intersting and easy to use technology.

    i was wondering how ADO.Net Data services works? i mean how the actually the URL converted to LINQ expressions or the interceptor predicates translated into LINQ and then SQL?

    is it possible to have a query interceptor that retruns 2 object collection??
    let say i have 2 business rule that i need to implement in my say Products Object Collection; or in other words can we have 2 query interceptor on one Object collection??

    Thanks
    Akhilesh Bhale
    Saturday, December 5, 2009 12:26 PM

Answers

  • Hi,

    I can't describe how exactly the URL -> LINQ conversion works here as it's a lot of code (and sometimes it's rather complex), it would be enough material for a shorter book. In most cases I would say it does what you would expect it to do. So for example "/Customers?$filter=ID eq 0" will translate to LINQ like "customers.Where(c => c.ID == 0)".
    It's similar for most of the other options (just pick the appropriate LINQ operator). The $expand and $select are a bit more tricky as well as navigations are and all put together it can get rather complex (if you throw your custom query interceptors and especially paging into the mix).

    So to state the highlevel rules: All the possible valid URL queries have well defined way of translating them into a LINQ expression. The translation of LINQ -> SQL (in case your data is provided by a SQL DB) is done by the provider. Most commonly that provider is Entity Framework and so the translation is done by the EF. In general it should just work :-).

    It is possible to have multiple query interceptors for one resource set (even more than just two). The way query interceptors work is that we get the expression by calling the query interceptor method and we stick it into a .Where(<your expression>) LINQ. If there are multiple query interceptors you just end up with multiple .Where calls (which works the same as if you combined the expressions with AND operator).

    Thanks,
    Vitek Karas [MSFT]
    • Marked as answer by Akhilesh Bhale Tuesday, December 8, 2009 6:51 AM
    Monday, December 7, 2009 1:04 PM
    Moderator

All replies

  • Hi,

    I can't describe how exactly the URL -> LINQ conversion works here as it's a lot of code (and sometimes it's rather complex), it would be enough material for a shorter book. In most cases I would say it does what you would expect it to do. So for example "/Customers?$filter=ID eq 0" will translate to LINQ like "customers.Where(c => c.ID == 0)".
    It's similar for most of the other options (just pick the appropriate LINQ operator). The $expand and $select are a bit more tricky as well as navigations are and all put together it can get rather complex (if you throw your custom query interceptors and especially paging into the mix).

    So to state the highlevel rules: All the possible valid URL queries have well defined way of translating them into a LINQ expression. The translation of LINQ -> SQL (in case your data is provided by a SQL DB) is done by the provider. Most commonly that provider is Entity Framework and so the translation is done by the EF. In general it should just work :-).

    It is possible to have multiple query interceptors for one resource set (even more than just two). The way query interceptors work is that we get the expression by calling the query interceptor method and we stick it into a .Where(<your expression>) LINQ. If there are multiple query interceptors you just end up with multiple .Where calls (which works the same as if you combined the expressions with AND operator).

    Thanks,
    Vitek Karas [MSFT]
    • Marked as answer by Akhilesh Bhale Tuesday, December 8, 2009 6:51 AM
    Monday, December 7, 2009 1:04 PM
    Moderator
  • Thanks Vitek. your post has all that i needed.

    Thanks Again. :)


    Akhilesh Bhale
    Tuesday, December 8, 2009 6:53 AM