locked
Data Service-Expand need help RRS feed

  • Question

  • Hi,

    I have to retrieve data from 2 entities. i have used foll query

    DataServiceQuery<vendorproduct> query = (DataServiceQuery<vendorproduct>)_ctx.vendorproductSet.AddQueryOption("$expand","product");

    Its retriving all the values from vendorproduct but not from product(none of the columns are retriving).

    product is Foreign key in vendorproduct. 

    Need some help.

    Thanks.........

    Monday, September 17, 2012 1:52 PM

All replies

  • You can also do the following: _ctx.vendorProductSet.Expand("Product") where Product is a navigation property. Can you hit this url in the browser and make sure you are getting the product entity expanded. If yes, then that should work for the LINQ query also. Also, if you have already queried vendorProductSet in the context, make sure to set the MergeOption to OverwriteChanges. Here's more about MergeOption: http://msdn.microsoft.com/en-us/library/system.data.services.client.mergeoption.aspx

    Hope this helps.

    Thanks

    Pratik


    This posting is provided "AS IS" with no warranties, and confers no rights.

    Monday, September 17, 2012 5:13 PM
    Moderator
  •  DataServiceQuery<Vendorproduct> query = (from p in context.ProductSet
                                                                join v in context.New_vendorproductSet on p.ProductId equals v.new_productid.Id
                                                                 select new product(p.ProductId, p.Name, p.New_manufacturernumber, v.New_vproductdescription, v.New_VendorProdId, v.New_Cost, v.New_Markup, v.New_ResellPrice)) as DataServiceQuery<Vendorproduct>;

    I tried this query also but getting error like object referance is not set to an instance of an object..

    Thanks.....

    Tuesday, September 18, 2012 6:46 AM
  • Using joins with WCF DS client usually doesn't work. The main reason is that OData in itself doesn't really support joins, at least not in the sense SQL does them. For example the join condition is usually troublesome to translate to OData. I'm surprised the above query does fail with NotSupported exception, but without a callstack and the exact exception, it's hard to say what's going on.

    Typically the sets you want to "join" must have a navigation property between them. So for example your Product entity should have a VendorProduct navigation property, or something like that. If that's the case, just try query = context.ProductSet.Expand("VendorProduct");

    Thanks,


    Vitek Karas [MSFT]

    Tuesday, September 18, 2012 8:54 AM
    Moderator
  • I used same query context.ProductSet.AddQueryOption("$expand", "product_VendorProduct");

    and used different object of context.

    Finally its retriving all the records.

    Thanks for valuable suggestion.

    Regards,

    Supriya

    Saturday, September 22, 2012 9:03 AM