This is a migrated thread and some comments may be shown as answers.

Onet to many and IndexOutOfRangeException

1 Answer 42 Views
LINQ (LINQ specific questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
samir kneife
Top achievements
Rank 1
samir kneife asked on 15 Feb 2010, 07:05 AM
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

1 Answer, 1 is accepted

Sort by
0
Damyan Bogoev
Telerik team
answered on 17 Feb 2010, 05:37 PM
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.
Tags
LINQ (LINQ specific questions)
Asked by
samir kneife
Top achievements
Rank 1
Answers by
Damyan Bogoev
Telerik team
Share this question
or