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

[Solved] Menu BindTo issue with EF Collection

4 Answers 49 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mohsin Bari
Top achievements
Rank 1
Mohsin Bari asked on 12 May 2010, 12:15 PM

I have got Category, CategoryProducts, and Products table in my DB

CategoryProducts has foreign key{CategoryID} to Category table and {ProductID} foreign key to Products table.

I used Entity Framework for my data access needs and to load use following syntax.

IList<Categories> categoriesToDisplay =  Context.Categories.Include("CategoryProducts").Where(x=>x.CategoryID= + categoryID +)

model.Categories = categoriesToDisplay;

Please note that categoriesToDisplay has collection of CategoryProducts which is of type EntityCollection, EntityCollection class
implements IEnumerable so binding should not be a problem using Telerik

and i am trying to use categoriesToDisplay collection using Telerik Menu control but dealing with an issue i could not resolve.

here is the code for Telerik.

<%=Html.Telerik().Menu()
    .Name("nav")
        .BindTo(Model, mappings =>
    {
        mappings.For<Categories>(binding => binding
                .ItemDataBound((item, category) =>
                {
                    item.Text = category.Name;
                })
                .Children(category => category.CategoryProducts ));
                mappings.For<CategoryProducts>(binding => binding
                .ItemDataBound((item, catProduct) =>
                {
                    item.Text = catProduct.Product.ProductName;
                }));
    })
%>

This is the error i get.

MainLayout.master: The best overloaded method match for
'Telerik.Web.Mvc.UI.MenuBuilder.BindTo(string, System.Action<Telerik.Web.Mvc.UI.MenuItem,Telerik.Web.Mvc.SiteMapNode>)'
has some invalid arguments

Can anyone shed any light on this

Thanks - Bari

4 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 12 May 2010, 12:37 PM
Hello Mohsin Bari,

Try adding the following line to your web.config (inside <compilation><assemblies /> </compilation>)

<add assembly="System.Data.Entity, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />

If using .NET 4 change the version number from 3.5.0.0 to 4.0.0.0.

This is required because the ASP.NET compiler will not know that those collections implement IEnumerable unless the EF assembly has been referenced.

Regards,
Atanas Korchev
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.
0
Mohsin Bari
Top achievements
Rank 1
answered on 12 May 2010, 12:58 PM
Hi Atanas,

thanks for your quick reply but i do already have this assembly referenced in my web.config file

regards - Mohsin Bari
0
Atanas Korchev
Telerik team
answered on 12 May 2010, 03:12 PM
Hello Mohsin Bari,

I am sending a sample project showing how to bind the menu to the Category->Product hierarchy from the Northwind database using EF.

I hope this helps,
Atanas Korchev
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.
0
Mohsin Bari
Top achievements
Rank 1
answered on 23 Aug 2010, 07:54 PM
Hi Atanas,

Thanks for last reply, our priorities were shifted and that's why i did not get a chance to look at code you send me.

now i have a different problem.

I have a list of IList<Categories> categories

and category has a column called Parent which is of a same type Cateory. just like Employee table with self refrences table for managers.

I wonder if we can use menu binding to render menu dynamically ?

Tags
Menu
Asked by
Mohsin Bari
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Mohsin Bari
Top achievements
Rank 1
Share this question
or