0

I have a sqlSever database, reverse engineered with EF 5

By default, lazy Loading is disabled, I need to tell the context dynamically if related entities should be included or not (lazy loading) by passing a parameter to my method :

 public static IEnumerable<Products> getProductsList(SearchQuery<Product> SearchQuery, bool isLazyLoading=false)
    {
        var context = new Context();
        var dataBaseInitializer = new DataBaseInitializer();
        dataBaseInitializer.InitializeDatabase(context);
        // if I need related entities, I Need to enable lazy loading
        context.Configuration.LazyLoadingEnabled = isLazyLoading;
        var ProductsRepository = new Repository<Product>(context);
        var ProductsList = ProductsRepository.Search(SearchQuery);
        return ProductsList;
    }

when i need the productList with no related entity, every thing is Ok,

When passing parameter 'isLazyLoading' to true, I see that it's well token in the context configuration, but no related entity is loaded,

I want to Avoid the "include" way ...

any Idea how to fix this please ?

SirZoro
  • 151
  • 1
  • 2
  • 10

1 Answers1

0

I need these two Lines :

context.Configuration.LazyLoadingEnabled = isLazyLoading;
context.Configuration.ProxyCreationEnabled = isLazyLoading;

( Proxy Creation is off by default)

Thanks My Lili !

SirZoro
  • 151
  • 1
  • 2
  • 10