OData WCF Data Services - Related data (by foreign key) is not displayed when a service is called

When I get data using the URL in the browser, I can see the related data, for example:

http: //localhost/services.svc/Dinners (1) / RSVPs

This lists 5 RSVPs for DinnerId = 1 in my case, but when I consume OData from another project, I can only get lunches, debugging the application shows that RSVPs = 0, while it should be 5.

I use the service by adding a service link to my project and returning the data through a very simple LINQ query:

public ActionResult Index()
        {
            var result = (from d in db.Dinners
                          select d);

            return View(result);
        }

Any idea why d.RSVPs = 0 when it should be filled? I use EF (code first), after which ScottGu ships with two very simple POCO classes for Dinner and RSVP. The Dinner class has a RSVP: collection public ICollection<RSVP> RSVPs { get; set; }, and the RSVP class points to Dinner with a foreign key public int DinnerId { get; set; }, and also the Dinner: class public Dinner Dinner { get; set; }.

Thank.

+3
source share
2 answers

-, virtual, POCO . virtual ICollection<RSVP> Dinner Dinner RSVP, , WCF ! virtual WCF , / ! , ! , , , EF POCO WCF.

, .

+1

Expand() .

( WCF)

- :

var result = (from d in db.Dinners.Expand("RSVPs")
                      select d);
+3

Source: https://habr.com/ru/post/1763909/


All Articles