2

i am using nhibenate by code mappings. for some reason it is doing eager fetching by default, whereas it should be lazy.

below is the mapping i have:

    public EntityMap()
    {
        Lazy(true);

        Id(x => x.Id, map =>
        {
            map.Generator(Generators.GuidComb);
            map.UnsavedValue("00000000-0000-0000-0000-000000000000");
        });
    }

so i tried to specify the lazy(true) in the base class, so that all the relationships are done with lazy loading.

i am also using mapping by convention, which is configured as below:

        // foreign key convention (many2one side)
        mapper.BeforeMapManyToOne += (insp, prop, map) => map.Lazy(LazyRelation.Proxy);
        mapper.BeforeMapManyToOne += (insp, prop, map) => map.Fetch(FetchKind.Select);

        // bag conventions (one2many side)
        mapper.BeforeMapBag += (insp, prop, map) => map.Lazy(CollectionLazy.Lazy);
        mapper.BeforeMapBag += (insp, prop, map) => map.Fetch(CollectionFetchMode.Select);

        // set conventions (one2many side)
        mapper.BeforeMapSet += (insp, prop, map) => map.Lazy(CollectionLazy.Lazy);
        mapper.BeforeMapSet += (insp, prop, map) => map.Fetch(CollectionFetchMode.Select);

so i have tried all the settings to make it fetch lazy, but its still fetching eager..

below is the query i am using to load the data:

        var session = SessionManager.GetCurrentSession();
        return session.QueryOver<Customer>().List();

the one/many to many mapping is specified as below:

          Bag(x => x.Customer, colmap => { }, map => map.OneToMany(x => { }));
          ManyToOne(x => x.Orders, map => {  map.NotNullable(true); });

please help!!!

all the settings mentioned above were added to make it lazy load, initially none of the settings where specified....

  • What exactly should be lazy loaded? How are your entities modelled? What SQL is executed? – cremor Jul 18 '13 at 10:14
  • i have ORDERS table which is referenced in CUSTOMER table, ORDERS should be lazily executed, sql query is mentioned in the question... –  Jul 18 '13 at 10:29
  • Are you sure that that mapping is correct? One order can have many customers, but one customer can only have one order? That seems like it's the wrong way around. Please post your entity classes and mapping classes so we can see what properties you have, of what type they are and how they are mapped. Also, I asked for the SQL that is executed, not the query you wrote. Look at the logging or use a NHibernate/SQL profiler. – cremor Jul 18 '13 at 10:37
  • if you are using json.net it does deserialize your proxy object, making queries... test it by making child objects null and then sending them to the page... –  Jul 19 '13 at 17:28

0 Answers0