Thanks Paul.

  Best regards,
  Daniel Mirapalheta

On Mar 11, 1:38 am, Paul Batum <paul.ba...@gmail.com> wrote:
> Hi Mira,
>
> Thanks for that, I understand the problem now. I also agree with your
> suggested fix. I wrote the following test for it:
>
>         [Test]
>         public void TernaryAssociationCanBeUsedWithElement()
>         {
>             new MappingTester<ManyToManyTarget>()
>                 .ForMapping(map =>
>                     map.HasManyToMany(x => x.MapOfChildrenToBools)
>                         .AsMap(null)
>                         .AsTernaryAssociation()
>                         .Element("IsManager", ep => ep.Type<bool>()))
>
>  .Element("class/map/index-many-to-many").HasAttribute("class",
> typeof(ChildObject).AssemblyQualifiedName)
>                 .Element("class/map/element").HasAttribute("type",
> typeof(bool).AssemblyQualifiedName);
>         }
>
> It now in my repository and will go into the official trunk with the next
> batch I send James.
>
> Thanks,
>
> Paul Batum
>
> On Mon, Mar 8, 2010 at 11:18 PM, Mira.D <mirapalh...@gmail.com> wrote:
> >  Hi Paul,
>
> >  Here are sample classes and mappings, note that those mappings
> > classes will work just with the change ("if (collection.Relationship !
> > = null)") at ManyToManyPart<TChild>.GetCollectionMapping, or else
> > you'll get a NullReferenceException. As I could see in the fnh unit
> > tests there are implementations for IDictionary of ValueTypes/
> > ValueTypes, Entities/Entities and ValueTypes/Entities but nothing of
> > Entities/ValueTypes, and I also agree that those interfaces are
> > confusing, I really would like to contribute in their design (I don't
> > like to be just "asking" for corrections or implementations) but for
> > now my time is running to short so I'll have to let this to some point
> > in the future :-( (I'll probably can breathe better in a couple
> > months).
>
> >    class Group
> >    {
> >        public long ID
> >        { get; private set; }
>
> >        public IDictionary<User, bool> Users
> >        { get; private set; }
> >    }
>
> >    class User
> >    {
> >        public long ID
> >        { get; private set; }
>
> >        public IDictionary<Group, bool> Groups
> >        { get; private set; }
> >    }
>
> >    class GroupMap:ClassMap<Group>
> >    {
> >        public GroupMap()
> >        {
> >            base.Table("Groups");
> >            base.Id(x => x.ID,
> > "ID").GeneratedBy.Native().Access.BackingField();
> >            base.HasManyToMany<IDictionary<User, bool>>(x =>
> > x.Users).Access.BackingField().
> >                Table("GroupUsers").ParentKeyColumn("GroupID").
> >                AsMap(null).AsTernaryAssociation("UserID",
> > "IsManager").
> >                Element("IsManager", x => x.Type<bool>());
>
> >            /* Expected:
>
> >                <map access="backfield" name="Groups"
> > table="GroupUsers" mutable="true">
> >                  <key>
> >                    <column name="GroupID" />
> >                   </key>
> >                  <index-many-to-many
> > class="ConsoleApplication22.User, ConsoleApplication22,
> > Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
> >                    <column name="UserID" />
> >                  </index-many-to-many>
> >                  <element type="System.Boolean, mscorlib,
> > Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
> >                    <column name="IsManager" />
> >                  </element>
> >                </map>
> >             */
> >        }
> >    }
>
> >    class UserMap : ClassMap<User>
> >    {
> >        public UserMap()
> >        {
> >            base.Table("Users");
> >            base.Id(x => x.ID,
> > "ID").GeneratedBy.Native().Access.BackingField();
> >            base.HasManyToMany<IDictionary<Group, bool>>(x =>
> > x.Groups).Access.BackingField().
> >                Table("GroupUsers").ParentKeyColumn("UserID").
> >                AsMap(null).AsTernaryAssociation("GroupID",
> > "IsManager").
> >                Element("IsManager", x => x.Type<bool>());
>
> >            /* Expected:
>
> >                <map access="backfield" name="Groups"
> > table="GroupUsers" mutable="true">
> >                  <key>
> >                    <column name="UserID" />
> >                   </key>
> >                  <index-many-to-many
> > class="ConsoleApplication22.Group, ConsoleApplication22,
> > Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
> >                    <column name="GroupID" />
> >                  </index-many-to-many>
> >                  <element type="System.Boolean, mscorlib,
> > Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
> >                    <column name="IsManager" />
> >                  </element>
> >                </map>
> >             */
> >         }
> >    }
>
> > On Mar 7, 9:05 pm, Paul Batum <paul.ba...@gmail.com> wrote:
> > > The fluent interface for maps is really confusing, and I'm partially
> > > responsible for that so I apologise.
>
> > > I think (though I am not certain) the problem in this case is that you
> > are
> > > calling both AsTernaryAssociation and Element. From what I can recall,
> > only
> > > one of those two methods should be called.
>
> > > Can you provide your classes and the expected xml? I would like to look
> > into
> > > this further.
>
> > > Thanks,
>
> > > Paul.
>
> > > On Mon, Mar 8, 2010 at 2:29 AM, Mira.D <mirapalh...@gmail.com> wrote:
> > > >  Refering:
>
> > > >http://groups.google.com/group/fluent-nhibernate/browse_thread/thread.
> > ..
>
> > > >http://groups.google.com/group/fluent-nhibernate/browse_thread/thread.
> > ..
>
> > > >  I have been trying to map a ternary many-to-many association just
> > > > like above links but got some problems. After founding no way to do
> > > > that I have changed some stuff in
> > > > ManyToManyPart<TChild>.GetCollectionMapping and got that working:
>
> > > >  Where we have:
>
> > > > // child columns
> > > > if (childColumns.Count == 0)
> > > >  ((ManyToManyMapping)collection.Relationship).AddDefaultColumn(new
> > > > ColumnMapping { Name = typeof(TChild).Name + "_id" });
>
> > > > foreach (var column in childColumns)
> > > >  ((ManyToManyMapping)collection.Relationship).AddColumn(new
> > > > ColumnMapping { Name = column });
>
> > > >  I surounded with "if (collection.Relationship != null)" so I can
> > > > make the following map:
>
> > > > class MyEntity
> > > > {
> > > >  public IDictionary<OtherEntity,ValueType> Others { get; private
> > > > set; }
> > > > }
>
> > > >  The mapping:
>
> > > >            base.HasManyToMany<IDictionary<OtherEntity, bool>>(x =>
> > > > x.Others).Access.BackingField().
> > > >                Table("TABLE").
> > > >                ParentKeyColumn("MY_ID").
> > > >                AsMap(null).AsTernaryAssociation("OTHER_ID", "VALUE").
> > > >                Element("VALUE", x => x.Type<ValueType>());
>
> > > >  It produces this hbm:
>
> > > >    <map access="backfield" name="Others" table="TABLE"
> > > > mutable="true">
> > > >      <key>
> > > >        <column name="MY_ID" />
> > > >      </key>
> > > >      <index-many-to-many class="OtherEntity">
> > > >        <column name="OTHER_ID" />
> > > >      </index-many-to-many>
> > > >      <element type="ValueType">
> > > >        <column name="VALUE" />
> > > >      </element>
> > > >    </map>
>
> > > >  Without this change the GetCollectionMapping throws null reference
> > > > exception because the call "Element("VALUE", x =>
> > > > x.Type<ValueType>());" set the collection relationship to null.
>
> > > >  Another strange thing is that I have to use
> > > > HasManyToMany<IDictionary<,>> because in
> > > > ManyToManyPart<TChild>.AsTernaryAssociation it first calls
> > > > EnsureGenericDictionary, witch check using the private field
> > > > childType, and after use typeof(TChild).GetGenericArguments(),
> > > > throwing a "index out of bounds", and if I'm mapping
> > > > IDictionary<ValueType, OtherEntity> I have to use
> > > > HasManyToMany<OtherEntity> or else my mapping will get <many-to-many
> > > > class="KeyParValue........">.
>
> > > >  Regards,
> > > >  DM
>
> > > > --
> > > > You received this message because you are subscribed to the Google
> > Groups
> > > > "Fluent NHibernate" group.
> > > > To post to this group, send email to
> > fluent-nhibern...@googlegroups.com.
> > > > To unsubscribe from this group, send email to
> > > > fluent-nhibernate+unsubscr...@googlegroups.com<fluent-nhibernate%2bunsubscr...@googlegroups.com>
> > <fluent-nhibernate%2bunsubscr...@googlegroups.com<fluent-nhibernate%252bunsubscr...@googlegroups.com>
>
> > > > .
> > > > For more options, visit this group at
> > > >http://groups.google.com/group/fluent-nhibernate?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Fluent NHibernate" group.
> > To post to this group, send email to fluent-nhibern...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > fluent-nhibernate+unsubscr...@googlegroups.com<fluent-nhibernate%2bunsubscr...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/fluent-nhibernate?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to fluent-nhibern...@googlegroups.com.
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en.

Reply via email to