0

I have a usercontrol in WPF project which it execute a select query which takes a long time this is the code

Entities1 context = new Entities1();                        
 ObservableCollection<E> _E = new ObservableCollection<E>();
CollectionViewSource ECollection = new CollectionViewSource();
ECollection = (CollectionViewSource)this.Resources["EResource"];
 this._E = new ObservableCollection<E>
            (from e in context.Es
             join eg in context.EQ_Gs on e.EQ_G_ID equals eg.EQ_G_ID
             join u in context.Us on e.U_ID equals u.U_ID
             join b in context.Bs on e.B_ID equals b.B_ID
             select e);           
            ECollection.Source = this._E;
            this.Grid_E.ItemsSource = this._E;
            this.Grid_E.DataContext = this._E;
            this.DataContext = ECollection; 
  

and table E has 30000 record it takes aound 2.5 min to load the usercontrol

VLAZ
  • 26,331
  • 9
  • 49
  • 67
pooooooneh
  • 19
  • 7
  • There's not much we can do to improve the performance of your code. You're not doing anything out of the ordinary and the query is only executed once. Any optimizations would have to be done on your database tables. The only other thing you could do is only select the fields of your `Es` object that you actually need... but we have no idea how you're actually using them in your views... – Jeff Mercado May 22 '16 at 07:06

1 Answers1

0

Thanks Jeff Mercado

I changed the query and used eager loading query it helped a lot and reduced loading time.

var query = context.E.include("B").tostring()
General Grievance
  • 4,555
  • 31
  • 31
  • 45
pooooooneh
  • 19
  • 7