locked
June 2011 CTP - How to query Navigation Properties of derived entities. RRS feed

  • Question

  •  

    Hi

     

    I am currently trying to evaluate EF and WCF Data Services. I installed the June 2011 CTP and using the Model First approach I designed an Entity hierarchy as follows:

     

     Computer <-- VirtualMachine <-- Snapshot ... where <-- represents the base/derived Entity relationship

     

    The question is how does the URI addressing the Navigation Property CurrentSnapshot look like?

    Accessing the Resource VirtualMachine is not a Problem using:

     

    http://localhost:1048/WcfDataService1.svc/Computers?$filter=isof('Devices.VirtualMachine')

     

    result:

     

    <?xml version="1.0" encoding="utf-8" ?>

    - <entry xml:base="http://localhost:1048/WcfDataService1.svc/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml">

    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/NetworkAdapters" type="application/atom+xml;type=feed" title="NetworkAdapters" href="Computers(4)/Devices.VirtualMachine/NetworkAdapters" />

    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/AssociatedHypervisor" type="application/atom+xml;type=entry" title="AssociatedHypervisor" href="Computers(4)/Devices.VirtualMachine/AssociatedHypervisor" />

    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/CurrentSnapshot" type="application/atom+xml;type=entry" title="CurrentSnapshot" href="Computers(4)/Devices.VirtualMachine/CurrentSnapshot" />

    <id>http://localhost:1048/WcfDataService1.svc/Computers(4)</id>

    <category term="Devices.VirtualMachine" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />

    <link rel="edit" title="Computer" href="Computers(4)/Devices.VirtualMachine" />

    <title />

    <updated>2011-07-18T12:14:46Z</updated>

    - <author>

    <name />

    </author>

    - <content type="application/xml">

    - <m:properties>

    <d:Id m:type="Edm.Int32">4</d:Id>

    <d:Name>VM1</d:Name>

    <d:Description>Virtual machine</d:Description>

    <d:RAM m:type="Edm.Int32">1024</d:RAM>

    <d:NumberOfCPUs m:type="Edm.Int32">1</d:NumberOfCPUs>

    <d:GuestOS>Win 7</d:GuestOS>

    <d:PowerState>Powerd On</d:PowerState>

    <d:IsTemplate>Nu</d:IsTemplate>

    </m:properties>

    </content>

    </entry>

     

    Using Computers(4)/Devices.VirtualMachine/CurrentSnapshot (href) brings up an error (resource not found)

     

    Any help is highly appreciated


    • Edited by Parolarul Monday, July 18, 2011 1:35 PM added Entity hierarchy
    Monday, July 18, 2011 1:17 PM

Answers

  • One thing comes to mind - are you using the Cassini local web server (I think it's called ASP.NET local web server), the one which comes with VS built-in. If that's the case, then the problem is in it. It simply can't handle correctly URLs which have the dot '.' character in the path (it thinks it's a file extension and does bad things with it).

    If that's the case you can either run this on the full IIS, or you can use the IIS Express, both whould work just fine.

    Thanks,


    Vitek Karas [MSFT]
    • Marked as answer by Parolarul Wednesday, July 20, 2011 9:39 AM
    Tuesday, July 19, 2011 9:14 AM
    Moderator

All replies

  • Hier is a picture of the model I use as an example.

    As you can see here the CurrentSnapshot is a Navigation Propertie of the VirtualMachine Entity.

    Monday, July 18, 2011 3:28 PM
  • Hi,

    404 (Resource not found) means that the value of the navigation property is null. Are you sure that the given virtual machine does have a current snapshot?

    Thanks,


    Vitek Karas [MSFT]
    Monday, July 18, 2011 7:37 PM
    Moderator
  • You can also verify that by running

    http://localhost:1048/WcfDataService1.svc/Computers/Devices.VirtualMachine?$expand=CurrentSnapshot

    If it is null you would see an empty m:inline element in the response.

    Thanks,


    Vitek Karas [MSFT]
    Monday, July 18, 2011 7:38 PM
    Moderator
  • Hi,

    Thanks for your answers. I get the same 404 (Resource not found) when using:

    http://localhost:1048/WcfDataService1.svc/Computers/Devices.VirtualMachine?$expand=CurrentSnapshot

     

    It seems to me that there is a general problem when using the links got back from the server (link element -> href).

     

    E.g. when I query for the first computer using: http://localhost:1048/WcfDataService1.svc/Computers(1)

    I get:

    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/NetworkAdapters" type="application/atom+xml;type=feed" title="NetworkAdapters" href="Computers(1)/Devices.Computer/NetworkAdapters" />

    <id>http://localhost:1048/WcfDataService1.svc/Computers(1)</id>

    <category term="Devices.Computer" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />

    <link rel="edit" title="Computer" href="Computers(1)/Devices.Computer" />

    <title />

    <updated>2011-07-19T08:30:55Z</updated>

    - <author>

    <name />

    </author>

    - <content type="application/xml">

    - <m:properties>

    <d:Id m:type="Edm.Int32">1</d:Id>

    <d:Name>Comp1</d:Name>

    <d:Description>The First One</d:Description>

    <d:RAM m:type="Edm.Int32">1024</d:RAM>

    <d:NumberOfCPUs m:type="Edm.Int32">2</d:NumberOfCPUs>

    </m:properties>

    </content>

    </entry>

     

    If I use the link provided by the server:  http://localhost:1048/WcfDataService1.svc/Computers(1)/Devices.Computer/NetworkAdapters

    I get a 404 Resource not found error.

    If I use: http://localhost:1048/WcfDataService1.svc/Computers(1)/NetworkAdapters

    I get the right Adapter Entity:

     

    - <entry>

    <link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/AssociateComputer" type="application/atom+xml;type=entry" title="AssociateComputer" href="NetworkAdapters(1)/AssociateComputer" />

    <id>http://localhost:1048/WcfDataService1.svc/NetworkAdapters(1)</id>

    <category term="Devices.NetworkAdapter" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />

    <link rel="edit" title="NetworkAdapter" href="NetworkAdapters(1)" />

    <title />

    <updated>2011-07-19T08:31:58Z</updated>

    - <author>

    <name />

    </author>

    - <content type="application/xml">

    - <m:properties>

    <d:Id m:type="Edm.Int32">1</d:Id>

    <d:Name>Net1</d:Name>

    <d:MACAddress>A3432B234224</d:MACAddress>

    <d:IPAddress>192.168.1.2</d:IPAddress>

    </m:properties>

    </content>

    </entry>

    <id>http://localhost:1048/WcfDataService1.svc/Computers(1)/NetworkAdapters</id>

    <title type="text">NetworkAdapters</title>

    <updated>2011-07-19T08:31:58Z</updated>

    <link rel="self" title="NetworkAdapters" href="NetworkAdapters" />

    </feed>

     

    Is there something I've overseen? As I am a newbie to this I wonder if there's something else done wrong along the way. 

     

    Thanks

     

    Tuesday, July 19, 2011 8:40 AM
  • One thing comes to mind - are you using the Cassini local web server (I think it's called ASP.NET local web server), the one which comes with VS built-in. If that's the case, then the problem is in it. It simply can't handle correctly URLs which have the dot '.' character in the path (it thinks it's a file extension and does bad things with it).

    If that's the case you can either run this on the full IIS, or you can use the IIS Express, both whould work just fine.

    Thanks,


    Vitek Karas [MSFT]
    • Marked as answer by Parolarul Wednesday, July 20, 2011 9:39 AM
    Tuesday, July 19, 2011 9:14 AM
    Moderator
  • Thanks Vitek, I'll give it a try.
    Wednesday, July 20, 2011 9:40 AM