Onet to many and IndexOutOfRangeException

2 posts, 0 answers
  1. samir kneife
    samir kneife avatar
    1 posts
    Member since:
    Jan 2010

    Posted 15 Feb 2010 Link to this post

    Hi,

    I am trying to get all produscts that match a specific Category using the using Northwind database for a test.
    In the ORM I have used only 3 tables for this test: Product, Category and Supplier.
    I have checked in the reverse mapping the option 'Create one-to-many list' for the field product in the Category Table.

    Now in my code I have the following for show all products list in a RadGrid for a specific category:
            protected void Page_Load(object sender, EventArgs e) { 
     
                var result = from cat in Scope.Extent<Category>() 
                             where cat.CategoryID == 1 
                             select new { Products = cat.Products }; 
                RadGrid1.DataSource = result; 
                RadGrid1.DataBind(); 
            } 
     

    The result return an IndexOutOfRangeException !
    What is wrong ?
    Thanks for help.
    Sam
  2. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 17 Feb 2010 Link to this post

    Hello samir kneife,

    The Linq query you are trying to execute is actually translating the select to a call of the SelectMany Linq method. The SelectMany method is implemented in the Telerik OpenAccess ORM but it will not be publicly available until the Q1 2010 release coming in March. For now, you could use the following workaround in order to achieve this goal:

    var result = from cat in Scope.Extent<Category>() 
                             join prod in Scope.Extent<Product>() on cat.CategoryID equals prod.CategoryID 
                             where cat.CategoryID == 1 
                             select prod;

    I think that will help you.

    Regards,
    Damyan Bogoev
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. DevCraft banner
Back to Top