Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

illegal access to loading collection error

I'm getting the error

Illegal access to loading collection

when I'm trying to get a list of variants belonging to a certain product. The NHibernate mapping is as below

<list name="Variants" lazy="false" cascade="save-update" inverse="false" table="PluginProduct_ProductVariant">
  <key column="ProductId" />
  <index column="Ordinal" />
  <one-to-many class="Plugin.Product.Business.Entities.Variant, Plugin.Product" />
</list>

I already tried chancing the laziness and inverse properties as suggested in other topics on this site, but they didn't do the trick.

I'm using NHibernate in combination with ASP.NET MVC and and I'm trying to loop through a collection of variant in my view. The view is calling the following method

        public ActionResult ShowProduct()
        {
        var id = new Guid(PluginData.PageParameters["Id"]);

        var variant = _variantService.GetVariantById(id);
        var product = variant.Product;

        return PluginView("ShowProduct.ascx", product);
        }

The above code runs without any problems. But when I debug just before returning the view I see that the list of variants which the product contains is empty. When I open more detailed debug information it's showing me the collection error.

In the view of my web application I'm trying to do the following

<%
foreach (var variant in Model.Variants)
{%>
    kleur: <%= variant.Color %>
    van: <%= variant.FromPrice %> voor: <%= variant.Price %>
<%} %>
like image 552
Rob Avatar asked Mar 22 '10 15:03

Rob


1 Answers

Got the problem solved! I ran into an other problem adding a product with a variant so i changed this intelligence in my controller. Then i ran into a problem with the mapping so i changes the mapping as below and it all worked!

    <list name="Variants" lazy="false" cascade="all" inverse="false">
  <key column="ProductId" />
  <index column="Ordinal" />
  <one-to-many class="Plugin.Product.Business.Entities.Variant, Plugin.Product" />
</list>
like image 106
Rob Avatar answered Oct 21 '22 12:10

Rob