locked
Returning nested objects thru service operation RRS feed

  • Question

  • I have a service operation that returns an IQueryable list of entities - "Outages". Each of these entities have a relation to a "Meta-data" entity that I would like to have returned by the service operation.

    It basically does this:

    [WebGet]
    public IQueryable<Outage> GetOutagesByDuration(int minutes)
    {
        var context = new MyContext();
        return context.Outages
            .Where(i => DbFunctions.DiffMinutes(i.StartDateTime, i.EndDateTime) >= minutes && i.EndDateTime != null);
    }

    My question is:

    How do I get the Service Operation to return the Meta-entity for each Outage-entity as well when calling it?

    I tried to add this to the query:

    .Include("OutageMetaData");


    (where "OutageMetaData" is the name of the navigation property on the Outage entity), but nothing is returned regardless of this.

    Is there a way to do this?

    /Jesper

    Copenhagen, Denmark


    /Jesper www.idippedut.dk

    Monday, November 18, 2013 10:47 PM

Answers

  • Hello,

    >>How do I get the Service Operation to return the Meta-entity for each Outage-entity as well when calling it?

    As far as I know, WCF Data Services doesn't support auto-expand of navigation properties on the server.

    The client explicitly has to ask for $expand='XXX' for this to work.

    If we use the URL, we should call it like below:

    http://localhost:17990/WcfDataService1.svc/Orders?$filter=OrderID eq 1&$expand=OrderDetails

    If we call it at the client side, we should call it like below:

    List<Order> result = db.Orders.Expand("OrderDetails").Where(o => o.OrderID == 1).ToList();

    And for more information regarding ‘expand’:

    http://msdn.microsoft.com/en-us/library/dd756366(v=vs.110).aspx

    If I have misunderstood, please let me know.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, November 19, 2013 4:33 AM
    Moderator