linq delay loading problem

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

Hi,

I have table in database "documents". I have column "binary" which is
VarBinary(MAX) with big content.
I decide to use lazy initialization. So in designer I set "delay
loaded" = true. I read my records:
var select = from d in db.Documents select d;
return select.ToList();
and I can see in debuger, that the property "Binary" has content.
Why ? I didn't use this property so I expected to be null until I use
it.

Thanks for help
 
Hi,

I have table in database "documents". I have column "binary" which is
VarBinary(MAX) with big content.
I decide to use lazy initialization. So in designer I set "delay
loaded" = true. I read my records:
var select = from d in db.Documents select d;
return select.ToList();
and I can see in debuger, that the property "Binary" has content.
Why ? I didn't use this property so I expected to be null until I use
it.

The debugger is not magical. It displays the values of properties by -
you guessed it! - calling the corresponding getter. So, by viewing the
object in the debugger, you "use" its properties, and trigger their
load.

This equally well applies to any lazy-init technique, not just LINQ to
SQL (assuming that's what you're using, since you haven't specified it
explicitly - next time, please do!).
 
The debugger is not magical. It displays the values of properties by -
you guessed it! - calling the corresponding getter. So, by viewing the
object in the debugger, you "use" its properties, and trigger their
load.

This equally well applies to any lazy-init technique, not just LINQ to
SQL (assuming that's what you're using, since you haven't specified it
explicitly - next time, please do!).

Does it mean, that I do everything right ?
I don't believe it if I can't check it ;)

Thanks for help
 
Does it mean, that I do everything right ?
I don't believe it if I can't check it  ;)

You should just enable tracing of SQL generated by the framework, and
see that the generated SELECT statements do not include the field that
you're lazy-loading (and that it generates additional SELECTs when you
access the property).
 
Back
Top