linq delay loading problem

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
 
P

Pavel Minaev

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!).
 
M

Mark

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
 
P

Pavel Minaev

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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top