-1

I have a usercontrol in wpf which contains a gridcontrol I've set gridcontrol datasource to a linq to ef join query like this:

var x = from B in x.B join E in X.E on B.E_ID equals E.E_ID
        select B
gridcontrol.datasource = x.tolist();

in xaml code I've set grid control columns as this:

first column FieldName = ID

second column FieldName = E.Name

since the second column is binded to E table,the gridcontrol loading is awfuly slow

plz give me a solution to increase the speed

pooooooneh
  • 19
  • 7
  • Calling `ToList()` on your query is unnecessary, a collection is a collection and the grid control will know what to do with it. With that said, your query is as basic as it can get. If that's not fast enough for you, you need to consider paging or setting some indices on your databases... the slowness is likely not from your code here. – Jeff Mercado Jun 19 '16 at 05:53
  • thanks friend but i have tested with and without .tolist() and checked many ways.if i delete the second column it works well and gridcontrol load very fast but the problem is i need to show the second column.when i use breakpoint the query return value fastly but the line of code which set gridcontrol datasource takes long time – pooooooneh Jun 19 '16 at 06:53
  • @pooooooneh "*when i use breakpoint the query return value fastly*" The query does not execute until you materialize it by either enumerating or calling `ToList` and similar. Also since you are selecting only `B` in the query, I don't see how it helps to get `E.Name`. If `E` is lazy loaded navigation property, you'd better use eager loading (something like `db.B.Include(b => b.E).ToList()`) – Ivan Stoev Jun 19 '16 at 07:43
  • thank you friend lvan Stoev.I used eager loading and the speed get better.Now it take around 8 sec .if i use listbox instead of gridcontrol the it takes half time to load around 4 sec.If you write your tip as an answer i can mark the question as solved.thanks and regards – pooooooneh Jun 20 '16 at 04:00

1 Answers1

0

with many thanks of lvan Stoev as he/she said,i changed my query and it was usefull.now it just take 8 second to load the usercontrol. the query: db.b.include("E").tolist()

pooooooneh
  • 19
  • 7