c# - Is it possible to limit based on navigational property id's? -


my model looks like:

city  cityblocks    houses 

so city can have many city blocks, , each city block can have many houses.

on particular page, have list of house id's want display.

the page expects city object, , loops , displays city blocks , houses.

one thing afraid of because of lazy-loading, if load things based on list of house id's, show city blocks , houses because of lazy-loading.

how can avoid situation page? (i can't disable lazy-loading globally use it).

update

so doing:

var repository = new genericrepository<home>(); var homes = repository.get(home => homeidlist.contains(home.id),                              includeproperties: "cityblock, cityblock.city")                             .tolist(); city city = homes.select(h => h.cityblock.city).distinct().firstordefault(); 

but, isn't working. when loop on city loads everything:

@foreach(var block in city.cityblocks) {    foreach(var house in block.houses)    {     } } 

disable lazy loading "locally" particular context instance using query:

var context = new mycontext(); context.configuration.lazyloadingenabled = false; 

it disabled context. next context instantiating have lazy loading enabled again.

edit

it should work single query:

try {     context.configuration.lazyloadingenabled = false;      // run query , materialize here (with .tolist(), or .first(), etc.) } {     context.configuration.lazyloadingenabled = true; } 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -