c# - How to Remove or Revert DataContext.DataLoadOptions? -


first let me start explaining use case:

say there database "cars". in database, each row might have make, model, enginetype, etc. have page view of single "car" record, displaying various stats. in page, have user control calculates , displys various mpg stats based on "car" record. user control passed "car" record via property, uses internally calculations.

inside user control, happens:

private void databindgrid() {     gridview.datasource = this.carrecord.getmpgstats(); } 

internal "carrecord", linq-to-sql query, using data context of carrecord. purpose of calculation, more efficient this:

private void databindgrid() {     dataloadoptions dlo = new dataloadoptions();      dlo.loadwith<car>(c => c.engine);      this.carrecord.datacontext.loadoptions = dlo;      gridview.datasource = this.carrecord.getmpgstats(); } 

for purpose of example, ignore whether or not may bad design user control passing in record & datacontext.

here issues i'm seeing:

  • the page may have set own load options before passing record user control, resulting in inefficient query.
  • the page may not want new settings specified user control when continues use car record itself.

so have 2 questions:

  1. what best way "clear" loadoptions? set datacontext.loadoptions = new dataloadoptions(); or = null;?
  2. is there way set sort of temporary loadoptions affect operation before reverting whatever before?

thanks in advance.

data load options have set before execution of first query. once query executes there nothing u can them.


Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

c++ - Convert big endian to little endian when reading from a binary file -