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

Get a List<T> from EntityQuery or EntitySet

1 Answer 94 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ala eddine
Top achievements
Rank 1
Ala eddine asked on 09 May 2012, 09:46 AM

public

 

public static IList<object> GenerateItems()
        {
 
            ModuleContext _context = new ModuleContext();
            EntityQuery<Fonctionnalite> q = _context.GetFonctionnalitesByModuleQuery(1);
            LoadOperation<Fonctionnalite> op = _context.Load(q);
           
            var result = new ObservableCollection<object>();
           
            foreach (var f in op.Entities.ToArray())
            {
                var item = new MainPageViewModel();
                item.Nom = f.Libelle;
                item.id = f.idFonctionnalite;
                foreach (var sf in f.SousFonctionnalites.ToArray())
                {
                    var child = new MainPageViewModel();
                    child.id = sf.idSousFonctionnalite;
                    child.Nom = sf.Libelle;
                    item.RelatedItems.Add(child);
                }
                result.Add(item);
            }
            return result;
        }

 
I want to display a Hierarchical Data in RadPanelBar form the entities Fonctionnalite and SousFoxtionnalite
( a Fonctionnalite has many SousFonctionnalite ) but i can't get a list from the Entityset<Fonctionnalite> !

1 Answer, 1 is accepted

Sort by
0
Accepted
Tina Stancheva
Telerik team
answered on 11 May 2012, 06:32 PM
Hi Ala,

This is probably a timing issue - when you start traversing the LoadOperation Entities collection, it's probably not yet generated. This is why it's better to implement your logic after the operation has completed. For that purpose you can handle the LoadOperation.Completed event:
public partial class MainPage : UserControl
{
    public MainPage()
    {
        InitializeComponent();
 
        NorthwindContext _northwindContext = new NorthwindContext();
        EntityQuery<Customer> q = _northwindContext.GetCustomersQuery();
        _northwindContext.Load(q).Completed += new EventHandler(op_Completed);
    }
 
    public static IList<object> GenerateItems(LoadOperation<Customer> op)
    {
            
        var result = new ObservableCollection<object>();
 
        foreach (var cust in op.Entities.ToArray())
        {
            var item = new MainPageViewModel();
            item.Name = cust.CompanyName;
            item.Id = cust.CustomerID;
            foreach (var ord in cust.Orders.ToArray())
            {
                var child = new MainPageViewModel();
                child.Id = ord.OrderID.ToString();
                child.Name = ord.ShipCountry;
                item.RelatedItems.Add(child);
            }
            result.Add(item);
        }
        return result;
    }
 
    private void op_Completed(object sender, EventArgs e)
    {
        xPanelBar.ItemsSource = GenerateItems(sender as LoadOperation<Customer>);
    }

I attached a sample solution demonstrating this approach. I hope it will get you started. Let us know if we can further assist you.

Regards,
Tina Stancheva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
PanelBar
Asked by
Ala eddine
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Share this question
or