subtable not retrievable from persistent class in a list

Thread is closed for posting
2 posts, 0 answers
  1. Jeremiah
    Jeremiah avatar
    1 posts
    Member since:
    Dec 2008

    Posted 10 Mar 2009 Link to this post

    I have a persistant class BasicProfile which contains a property HomeLocation.
    The HomeLocation refers to a Location table.

    Now I have a method:
     public void retrieveBasicProfileMatches(
                ref string query, 
                ref List<BasicProfile> searchResults,
                ref IObjectScope objectScope)

    The List is populated within the method.
    After the call, I iterate through the list with a foreach but I get a null reference when trying to reference my HomeLocation data.
    However, if I load a single BasicProfile using the id retrieved from the list, then the HomeLocation data is available:

    foreach (BasicProfile b in searchResults)
    {
        ...
       // something = b.HomeLocation.Province + ", " + b.HomeLocation.CountryCode;
       // bombs... but the following works
       BasicProfile redundant = load(b.MemberId, objectScope).
       something = redundant.HomeLocation.Province + ", " + b.HomeLocation.CountryCode; //works
    ...
    }

    Any ideas?  note the objectScope is in scope the whole time.
  2. PetarP
    Admin
    PetarP avatar
    754 posts

    Posted 12 Mar 2009 Link to this post

    Hi Jeremiah,
    we tried to reproduce your case. We used the order table from the northwind database. The order has a reference to employee.
    static void Main(string[] args) 
            { 
                IObjectScope scope = ObjectScopeProvider1.GetNewObjectScope(); 
                string Query = "Select * From OrderExtent"
                List<Order> myOrderList = new List<Order>(); 
                RetrieveOrders(ref Query,ref myOrderList,ref scope); 
                foreach (Order ord in myOrderList) 
                { 
                    Console.WriteLine(ord.Employee.FirstName); 
                    Console.ReadKey(); 
                } 
                 
           } 
            public static void RetrieveOrders(ref string Query, ref List<Order> OrderList, ref IObjectScope scope) 
            { 
     
                Query<Order> result = scope.GetOqlQuery<Order>(Query); 
                QueryResultList<Order> myResult = result.ExecuteList(); 
                OrderList = myResult.ToList(); 
            } 
    The following piece of code retrieves all orders and prints the names of the employees who carried the order.This code works in our case. In order to aid you with your problem would it be possible for you to recreate the problem in a simple application and send it to us.

    Sincerely yours,
    PetarP
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top