c# - LINQ performing multiple queries instead of a single "joined" query -
i not linq power user means, can fumble way around on basic level. have question regarding how linq formulates it's query "strategy". try explain best can , write extremely dumbed-down example memory.
i have data model contains multiple database views. let's views have column structure follows:
personview
personviewid | surname | givenname | otherviewid ------------------------------------------------ otherview view
otherviewid | personviewid | name --------------------------------- after setting primary keys view (personview.personviewid / otherview.otherviewid) , setting appropriate fields non-nulable, create association between personview.personviewid (parent) otherview.personviewid (child). set "one one" , write code consume it:
stringbuilder s = new stringbuilder(); foreach(personview p in dc.personviews) { s.appendline(p.otherviews.name + "<br />"); } after noticing extremely poor performance, profiled database , noticed doing query each of personview's in foreach statement.
at point rewrote query , replaced association in dbml join in linq query, profiled database , queried db expected, once.
i thinking db being queried, not sure debugging that. can point me in proper direction on me improve performance of using associations or stuck using join's accomplish need?
thanks :)
this caused lazy loading - can around applying loadwith() (the equivalent of ef's include() linq sql) , doing query afterwards:
var dlo = new dataloadoptions(); dlo.loadwith<personview>(p => p.otherviews); dc.loadoptions = dlo; //your query here
Comments
Post a Comment