locked
Inheritance and queries RRS feed

  • Question

  • I am trying to query for an object of a specific subtype, by Id, and fetch a property of that subtype. When I use the following code:

    EntityContext.Partners
      .OfType<Client>()
      .AsDataServiceQuery()
      .Expand(i => i.PublicStyle)
      .Where(i => i.Id == Object.Id)
      .AsDataServiceQuery();
    (AsDataServiceQuery simply casts it back to a DataServiceQuery)

    The following URL is created:

    http://localhost:12329/wpf.services/EntityDataService.svc/Partners/ISIS.Private.Wpf.Entities.Client(guid'8889de72-afc6-4af6-b875-05a876e44cf7')?$expand=PublicStyle

    And the following error occurs:

    The request URI is not valid. Since the segment 'Partners' refers to a collection, this must be the last segment in the request URI. All intermediate segments must refer to a single resource.

    I cannot figure out what the proper way to do this is. What SHOULD the proper URL be? I am implementing a custom ResourceType provider and stuff, so it might be something on the server side... but... as far as I can tell, the client side Linq is generating a bad URI which fails before it even hits my code.

    Saturday, February 9, 2013 12:00 AM

Answers

  • The looks mostly correct. Couple of questions:

    - Are you using OData V3 (since type casts in the URL require V3). This means WCF DS 5.0 or higher and you have to allow V3 on the server.

    - The ISIS.Private.Wpf.Entities.Client, is it really the server side namespace and entity type name? (The Wpf in the name seems suspicious to me). If it's the client side type name, then you're probably missing implementation of the DataServiceContext.ResolveName on the client.

    Thanks,


    Vitek Karas [MSFT]

    Monday, February 11, 2013 8:47 AM
    Moderator

All replies

  • The looks mostly correct. Couple of questions:

    - Are you using OData V3 (since type casts in the URL require V3). This means WCF DS 5.0 or higher and you have to allow V3 on the server.

    - The ISIS.Private.Wpf.Entities.Client, is it really the server side namespace and entity type name? (The Wpf in the name seems suspicious to me). If it's the client side type name, then you're probably missing implementation of the DataServiceContext.ResolveName on the client.

    Thanks,


    Vitek Karas [MSFT]

    Monday, February 11, 2013 8:47 AM
    Moderator
  • "Are you using OData V3 (since type casts in the URL require V3). This means WCF DS 5.0 or higher and you have to allow V3 on the server."

    Yes

    "The ISIS.Private.Wpf.Entities.Client, is it really the server side namespace and entity type name? (The Wpf in the name seems suspicious to me). If it's the client side type name, then you're probably missing implementation of the DataServiceContext.ResolveName on the client."

    The WPF is proper. It's a service designed specifically for an app named "ISIS.Private.Wpf". There's a long history there...

    I'm honestly unsure what the proper server side type name should be. I'm generating the client side using the built in service reference box. It is creating ResolveNameFromType using "ISIS.Private.Wpf.Entities". The namespace of the full type on the server side is "ISIS.Private.Wpf.Services.Entitities.Client" However, the ContainerNamespace of my DataServiceProvider is set to "ISIS.Private.Wpf.Entities". The reason for this is that I don't want to expose the actual full server side type name to clients. I'm guessing the client side is being generated with the ContainerNamespace, and yet the server isn't cool resolving from that namespace?

    [EDIT]

    I may have just found my problem... I might be filling the ResourceTypes with the real server side name, and not the name I want them to have. 

    [EDIT2]

    Problem solved. My TryResolveResourceType method wasn't resolving namespaces properly. I've corrected that, and now it's working just fine. Thanks!

    Monday, February 11, 2013 4:43 PM