wpf - When does the defered execution occur? -


i've got situation want fetch data database, , assign tooltips of each row in listview control in wpf. (i'm using c# 4.0.) since i've not done sort of thing before, i've started smaller, simpler app ideas down before attempt use them in main wpf app.

one of concerns amount of data potentially come down. reason thought use linq sql, uses deferred execution. thought , not pull down data until user passes mouse on relevant row. this, i'm going use separate function assign values tooltip, database, passed upon parameters need pass relevant stored procedures. i'm doing 2 queries using linq sql, using 2 different stored procedures, , assigning results 2 different datagrids.

even though know linq sql use deferred execution, i'm beginning wonder if of code i'm writing may defeat whole intent of using linq sql. example, in testing in simpler app, choosing several different values see how works. 1 selection of values brought no data back, there no data given parameters. thought potentially cause user confusion, thought check count property of list assign running dbml associated method (related stored procedure). thinking it, think necessary linq run query, in order give me result count property. not correct?

if eliminate call list's count property, i'm still wondering if might have problem; if linq may still invoked, because i'm associating tooltip control via function call?

you should use any(), not count(), any() cause query executed - after all, can't determine whether or not there rows in result set without executing query. there's executing query, , there's fetching result set. any() fetch 1 row, count() fetch them all.

that said, think having non-instantaneous operation occurs on mouseover bad idea. there build of outlook, once, displayed helpful tooltip when moused on print button. less helpfully, got data tooltip calling system function finds out printers available. you'd reaching menu, , button grab mouse pointer , ui freeze 2 seconds while went out , figured out how display tooltip weren't asking for. still hate program today. don't guy.

a better approach tooltip data asynchronously after populating visible data on screen. it's easy enough create backgroundworker fetches data datatable, , make datatable available view models in runworkercompleted event handler. (do there don't updates ui-bound data on ui thread.) can implement tooltip property in view model returns default value (probably null, maybe "fetching data...") if datatable containing tool tip data null, , calculates value if it's not. should work admirably. can implement property-change notification tooltip still updated if user keeps mouse pointer on while you're fetching data.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -