FetchStrategy does not return related objects

2 posts, 0 answers
  1. Art Kedzierski
    Art Kedzierski avatar
    107 posts
    Member since:
    Nov 2009

    Posted 18 Jun 2013 Link to this post

    I have a Silverlight project utilizing ORM. in my Web project I have created a method to fetch a custom class and its related data.

    public IQueryable<Web.Appointment> GetAppointmentsByResource(int rscID)
    {
        FetchStrategy fetch = new FetchStrategy();
        fetch.LoadWith<Web.Appointment>(f => f.Appt2Rescs);
        fetch.LoadWith<Web.Appointment>(f => f.Attendees);
        this.DataContext.FetchStrategy = fetch;
     
        return this.DataContext.Appointments
                    .Where(w => w.Appt2Rescs.Any(r => r.ResourceFK == rscID));
    }

    I am not seeing the related ILists reflected in the Silverlight project when I implement the method:

    LoadOperation<Web.Appointment> loadAppts = dc.Load(dc.GetAppointmentsByResourceQuery(aid));
    loadAppts.Completed += (s, a) =>
    {
        foreach (Web.Appointment app in loadAppts.Entities)
        {
            foreach (Attendee att in app.Attendees)  //app.Attendees is not there
            {
                Console.WriteLine(att.UserName);
            }
        }
    }

    I have tried both the FetchStrategy and the simpler Include() method (noted below for reference) to no avail. All I get in the Silverlight project is the top tier Web.Appointment objects. What am I not doing right?

    public IQueryable<Web.Appointment> GetAppointmentsByResource(int rscID)
    {
        return this.DataContext.Appointments
                    .Include(a => a.Appt2Rescs)
                    .Include(a => a.Attendees)
                    .Where(w => w.Appt2Rescs.Any(r => r.ResourceFK == rscID));
    }
  2. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 21 Jun 2013 Link to this post

    Hello Art,

     Can you please verify that the objects are correctly loaded on your server? It is not impossible that our lazy loading is preventing the objects from being serialized. Can you please try to access one of the objects before returning it to the client and see if that changes the behaviour?

    Regards,
    Petar
    Telerik
    OpenAccess ORM Q2 2013 brings you a more powerful code generation and a unique Bulk Operations support with LINQ syntax. Check out the list of new functionality and improvements shipped with this release.
  3. DevCraft banner
Back to Top