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]>
> 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
-~----------~----~----~----~------~----~------~--~---