سؤال

For an ASP.Net project I'm using (Fluent) NHibernate for the persistence and JQGrid for displaying the data in a table. But when I want to use the AutoComplete feature of JQGrid I get an System.ArgumentException: Column 'HibernateLazyInitializer' does not belong with this table. while obtaining the data in an AJAX Request. But this error occurs only sporadically and when some kind of proxyclass is used in the list. Therefore I think it has something to with the lazyloading of NHibernate.

protected new void Page_Load(object sender, EventArgs e)
  {
     base.Page_Load(sender, e);
     _jqAutoComplete.DataSource = Session.CreateCriteria<Domain.Brand>()
            .List<Domain.Brand>();
     _jqAutoComplete.DataBind();
  }

Usually the lazyloading is a pretty cool feature. Only in this case it leads to an error and therefore I don't want to disable it in the whole project. So, is there a way of modifying the CreateCriteria for not using LazyLoading but EagerLoading in this one case? Or is there something else I'm missing? If there is a good tutorial for understanding LazyLoading I would be glad too.

هل كانت مفيدة؟

المحلول

I solved the problem differently. Now I'm converting the Domain-Object into the corresponding object from the ViewModel. I'm using ValueInjecter for accomplishing the mapping.

protected new void Page_Load(object sender, EventArgs e)
  {
     base.Page_Load(sender, e);

     var objList = service.getList<Domain.Brand>();
     IList<V> list = new List<ViewModel.Brand>();

     foreach (var el in objList)
     {
        var brand = new ViewModel.Brand();
        list.Add(brand.InjectFrom<FlatLoopValueInjection>(el));
     }

     _jqAutoComplete.DataSource = list;
     _jqAutoComplete.DataBind();
  }

That solution works for me but I'm not totally happy with that.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top