Yes, found my error.. I missed in the example that in the child I have an 
enum property.. that one was causing the issue.
Using a convention solved the issue (
http://stackoverflow.com/questions/3531937/enum-to-integer-mapping-causing-updates-on-every-flush
)

Thanks!!

El jueves, 10 de octubre de 2013 10:36:31 UTC-3, Ricardo Peres escribió:
>
> Have you tried setting the HasMany to Inverse?
>
> public class ParentMap : ClassMap<Parent>
> {
>     public ParentMap()
>     {
>         Id(x => x.Id)
>             .GeneratedBy.Identity()
>             .UnsavedValue(0);
>         Version(x => x.HB_Version);
>         Map(x => x.Name, "Name")
>             .Not.Nullable();
>         HasMany<ContainerHistory>(x => x.History)
>             .AsSet()
>             .LazyLoad()
>             .Inverse() //here
>             .Cascade.AllDeleteOrphan();
>     }
> }
>
> RP
>
>
> On Wednesday, October 9, 2013 8:57:58 PM UTC+1, José Juniors Rocaspana 
> wrote:
>>
>> Hello all, I'm running into some issues with NH and child collections.
>> Currently I'm using NHibernate + Fluent; t
>>
>> Here my entities:
>>
>> public class Parent : Entity
>> {
>>     private ICollection<Child> m_children = new HashedSet<Child>();
>>
>>     public virtual string Name { get; set; }
>>     public virtual ICollection<Child> Children { get { return m_children; 
>> } set { m_children = value; } }
>> }
>>
>>
>> public class Child : Entity
>> {
>>     public virtual Parent ParentObj { get; set; }
>>     public virtual String MoreInformation { get; set; }
>> }
>>
>> And here my mappings:
>>
>> public class ParentMap : ClassMap<Parent>
>> {
>>     public ParentMap()
>>     {
>>         Id(x => x.Id)
>>             .GeneratedBy.Identity()
>>             .UnsavedValue(0);
>>         Version(x => x.HB_Version);
>>         Map(x => x.Name, "Name")
>>             .Not.Nullable();
>>         HasMany<ContainerHistory>(x => x.History)
>>             .AsSet()
>>             .LazyLoad()
>>             .Cascade.AllDeleteOrphan();
>>     }
>> }
>>
>> public class ChildMap : ClassMap<Child>
>> {
>>     public ChildMap()
>>     {
>>         Id(x => x.Id)
>>             .GeneratedBy.Identity()
>>             .UnsavedValue(0);
>>         Version(x => x.HB_Version);
>>         References(x => x.Container).Index("IX_Container");
>>         Map(x => x.MoreInformation, "MoreInformation").Not.Nullable();
>>     }
>> }
>>
>> The problem is that whenever I add a new item to the Parent.Children 
>> collection, an update is performed on all previous child items of the 
>> collection.. using NHibernate Profiler I found out that only the version 
>> (HB_Version field) is being updated (incremented by 1 each time I add a new 
>> item to the collection).
>>
>> I tried using .Not.OptimisticLock() in the HasMany map and even in the 
>> References mal (in ChildMap) but the problem remains.
>>
>> I'm missing something? Or it's the desired behaviour that every time the 
>> parent is modified all the child elements are updated aswell?
>>
>> Any help or suggestion will be greatly appreciated!!!
>>
>> Kind regards,
>> José.-
>>
>> P.S.: Please excuse my english :)
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to