-1

I'm fetching a large Amount of data from RIA Service. the return type have group of objects like RouteA, HistroyRouteA. HistroyLogRouteA all have records for different years with same Unique Key.

I have to Bind this data dynamically to a RadGridView. Always I have unknown columns in result. For this I followed

http://blogs.telerik.com/vladimirenchev/posts/11-09-28/dynamic-binding-for-your-silverlight-applications.aspx

http://www.telerik.com/forums/rowdetailstemplate-binding-with-dynamic-data

And build My data Collection with Code :

    private void OnShowPreviousYear(object parameter)
    {
        GridViewHeaderCell cell = parameter as GridViewHeaderCell;
        var head = cell.Column.Header;
        this.context.Load<Route>(this.context.GetRoutesQuery(), LoadBehavior.MergeIntoCurrent, OnRouteHistoryLoadComplete, null);
    }

    private void OnRouteHistoryLoadComplete(LoadOperation<Route> lo)
    {
        object ro = null;
        if (lo.Entities != null)
        {

            this.context.Load<Routeshistory>(this.context.GetRouteshistoriesQuery(), LoadBehavior.MergeIntoCurrent, (lp) =>
            {
                Route recent = lo.Entities.FirstOrDefault();
                int year =(int)recent.Hpmsyear-1;
                var rows = this.context.Routes.Join(this.context.Routeshistories,
                    r => r.Routeid.ToString(),
                    h => h.Routeid.ToString(),
                    (r, h) => new { r, h });//.Where(t => t.r.Routeid == t.h.Routeid );


                RoutesGridData = new ObservableCollection<DataRow>();
                int count = 0;                    
                foreach (var tmpR in rows)
                {
                    //Debug.WriteLine(tmpR.r.Routeid + " -- " + tmpR.h.Routeid);
                    if (count < 50)
                    {
                        DataRow row = new DataRow();

                        if (tmpR.r is Route)
                        {
                            Type type = tmpR.r.GetType();
                            foreach (PropertyInfo info in type.GetProperties())
                            {
                                // Debug.WriteLine(info.Name + "--- NAME OF PRR");
                                var val = info.GetValue(tmpR.r, null);
                                if (!info.Name.Equals("EntityConflict")
                                    && !info.Name.Equals("ValidationErrors")
                                    && !info.Name.Equals("HasValidationErrors")
                                    && !info.Name.Equals("EntityState")
                                    && !info.Name.Equals("HasChanges")
                                    && !info.Name.Equals("IsReadOnly")
                                    && !info.Name.Equals("EntityActions"))
                                {
                                    row[info.Name] = val;
                                }
                            }
                        }
                        // other tables...
                        RoutesGridData.Add(row);

                    }
                    count++;                        
                }

            }, null);
        }
     //   var b = ro;
    }

this code works fine for small record like 50 rows. but I when It try to convert all data it become slow. and screen crashes. I think this is because of Reflection. Is there any other way to convert my fetch data into Dictionary? Means I can map my table to dictionary in Entity Framework or Linq can do this for me without getting my code slow etc.

My Entities are mapped with EF 6 & I m using Deart oracle connector.

akirti
  • 179
  • 2
  • 15

1 Answers1

0

Due to reflection it was getting extremely slow so I did in during Linq query it's working for a while what data I have with me.

var rowss = this.context.Routes.Join(this.context.Routeshistories,
                      r => r.Routeid,
                      h => h.Routeid,
                      (r, h) => new DataRow(
                          (from x in r.GetType().GetProperties() select x).Where(x => x.Name != "EntityConflict"
                               && x.Name != "ValidationErrors"
                               && x.Name != "HasValidationErrors"
                               && x.Name != "HasChanges"
                               && x.Name != "EntityState"
                               && x.Name != "IsReadOnly"
                   && x.Name != "EntityActions")
                   .ToDictionary(x => x.Name, x => (x.GetGetMethod().Invoke(r, null) == null ? "" : x.GetGetMethod().Invoke(r, null))),
                          (from x in h.GetType().GetProperties() select x).Where(x => x.Name == head)
                          .ToDictionary(x => x.Name + "-" + year.ToString(), x => (x.GetGetMethod().Invoke(h, null) == null ? "" : x.GetGetMethod().Invoke(h, null))))
                       );//   , new EqualityComparerString()

RoutesGridData = new ObservableCollection<DataRow>(rowss);
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
akirti
  • 179
  • 2
  • 15