locked
How to get the ResourceSet Names in SelectMany expression from oData? RRS feed

  • Question

  • Hi

    URL : http://localhost:57070/DataService/WcfTestDataService.svc/Categories(1)/Products

    Gaol: Retrieves all the Product of the selected Category

    Expression Returned:
    value(OurNamespace.ReportQueryable`1[OurNamespace.DspResource]).Where(element => (Convert(GetValue(element, value(System.Data.Services.Providers.ResourceProperty))) = 1)).SelectMany(element => GetSequenceValue(element,
    value(System.Data.Services.Providers.ResourceProperty)))

    Attempts: Tried using DspMethodTranslatingVisitor.TranslateExpression to find the ResourceSet Names (eg, Categories, Products), but no luck

    Anyone can suggest a good way to work this out?  

    Regards,
    Matt

    Friday, July 2, 2010 2:20 AM

Answers

  • Hi,

    For detailed explanation of the expression trees generated for navigations, take a look at this post: http://blogs.msdn.com/b/vitek/archive/2010/06/22/data-services-expressions-part-7-navigation.aspx

    As for your question, there are two parts to it. One is the Categories and the other is the Products.

    Categories are the root of the query. In the expression tree it is the custom expression returned from the IDataServiceQueryProvider.GetQueryRootForResourceSet (for query root discussion refer to this post please: http://blogs.msdn.com/b/vitek/archive/2010/03/03/data-services-expressions-part-2-the-query-root.aspx). In your sample above it seems to be a constant expression with an instance of the ReportQueryable<DspResource>. You should be able to get this from the expression tree. This expression is totally under your control (since you implement the IDataServiceQueryProvider), so you can easily return an expression tree node which will hold the ResourceSet it represents as well.

    As for Products, the body of the SelectMany contains a property access, the call to the GetSequenceValue method. This call passes the ResourceProperty instance as the second parameter. This is a constant expression with the value of the ResourceProperty. So you can grab that from the expression tree there. Once you have the ResourceProperty, that property should be a ResourceSetReference property kind, which points to the ResourceType (in this case Product resource type). Also by calling the IDataServiceMetadataProvider.GetResourceAssociationSet you can determine the target ResourceSet for this navigation.

    Thanks,


    Vitek Karas [MSFT]
    • Marked as answer by Matthew Kwan Wednesday, July 7, 2010 11:19 PM
    Friday, July 2, 2010 2:04 PM
    Moderator

All replies

  • Hi,

    For detailed explanation of the expression trees generated for navigations, take a look at this post: http://blogs.msdn.com/b/vitek/archive/2010/06/22/data-services-expressions-part-7-navigation.aspx

    As for your question, there are two parts to it. One is the Categories and the other is the Products.

    Categories are the root of the query. In the expression tree it is the custom expression returned from the IDataServiceQueryProvider.GetQueryRootForResourceSet (for query root discussion refer to this post please: http://blogs.msdn.com/b/vitek/archive/2010/03/03/data-services-expressions-part-2-the-query-root.aspx). In your sample above it seems to be a constant expression with an instance of the ReportQueryable<DspResource>. You should be able to get this from the expression tree. This expression is totally under your control (since you implement the IDataServiceQueryProvider), so you can easily return an expression tree node which will hold the ResourceSet it represents as well.

    As for Products, the body of the SelectMany contains a property access, the call to the GetSequenceValue method. This call passes the ResourceProperty instance as the second parameter. This is a constant expression with the value of the ResourceProperty. So you can grab that from the expression tree there. Once you have the ResourceProperty, that property should be a ResourceSetReference property kind, which points to the ResourceType (in this case Product resource type). Also by calling the IDataServiceMetadataProvider.GetResourceAssociationSet you can determine the target ResourceSet for this navigation.

    Thanks,


    Vitek Karas [MSFT]
    • Marked as answer by Matthew Kwan Wednesday, July 7, 2010 11:19 PM
    Friday, July 2, 2010 2:04 PM
    Moderator
  • Hi Vitek, I still cannot get my head around this.  Are you able to to show me show codes of what you suggested above?

    Regards,

    Matt

    Sunday, July 4, 2010 5:19 AM