Thanks for your reply.

The initialization of the IList was not the issue, I actually
initialized it upon population therefor it didn't issue an exception for
it (I have however rewritten it now).

The fact remains though, and I seem to have nailed down what causes it.
If I add "Index" to the HasMany-attribute, it magically works. Seems
like it cannot automatically generate the index-column, nor any name for
it, therefore NHibernate throws the IndexOutOfBoundException.

[HasMany(
    typeof( CartDiscount ),
    Access = PropertyAccess.FieldCamelcase,
    Cascade = ManyRelationCascadeEnum.All,
    RelationType = RelationType.List,
    Index = "order_index"
)]

However, I tried finding any mentioning of this in the documentation but
couldn't find any, and preferrably it should throw an understandable
exception if "Index" is missing when using a List or Map relationtype,
if it isn't generated by default. Hopefully this post will help someone
in the future, and I try filing a bug-report.



Markus Zywitza wrote:
> If you put the HasMany on the IEnumerable, NH tries to add things to
> the IEnumerable. I think the error is an NH bug, because the value is
> not tested against null before checking the character. Nonetheless,
> your approach won't function.
>
> Use instead a protected or private IList for mapping and create a
> public IEnumerable that reads that IList. You should also initialize
> the backing field with a List. NH doesn't know what implementation of
> IList you want, you could have even rolled your own!
>
> So this should work:
>       private IList<CartDiscount> _applicableDiscounts = new
> List<CartDiscount>();
>        
>       [HasMany(
>             typeof( CartDiscount ),
>             Access = PropertyAccess.FieldCamelcase,
>             Cascade = ManyRelationCascadeEnum.AllDeleteOrphan,
>             RelationType = RelationType.List
>         )]
>       protected IList<CartDiscount> _ApplicableDiscounts { .... }
>        
>       public IEnumerable<CartDiscount> ApplicableDiscounts { get {
> return _ApplicableDiscounts;} }
>
> -Markus
>
> 2009/7/15 Jimmy Shimizu <[email protected]
> <mailto:[email protected]>>
>
>     Hi, I came across an issue when mapping an HasMany-collection.
>
>     with the following code:
>
>           private IList<CartDiscount> applicableDiscounts;
>            
>           [HasMany(
>                 typeof( CartDiscount ),
>                 Access = PropertyAccess.FieldCamelcase,
>                 Cascade = ManyRelationCascadeEnum.AllDeleteOrphan,
>                 RelationType = RelationType.List
>             )]
>             public IEnumerable<CartDiscount> ApplicableDiscounts { .... }
>
>
>     My app fails to start with the following exception:
>
>     [IndexOutOfRangeException: Index was outside the bounds of the array.]
>        NHibernate.Mapping.Column.set_Name(String value) in 
> c:\CSharp\NH\nhibernate\src\NHibernate\Mapping\Column.cs:85
>
>         
>
>     Looking at the sourcecode, I see this:
>
>
>     public string Name
>     {
>         get { return name; }
>         set
>         {
>     85:    if (value[0] == '`')
>
>
>
>     and when debugging, I see that value is actually an empty string.
>     however, if I change the RelationType on the collection to "Set",
>     the problem goes away. Why is that? Is it trying to add some
>     secret column which doesn't get a name correctly or something?
>
>     Maybe this should go to NH-list instead, but it's partly an
>     ActiveRecord-issue.
>
>     What is the default RelationType for a generic IList<>? Bag or List?
>
>
>
>
> >

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to