On 27 Jan, 04:17, Ryan Aimel Estandarte
<[email protected]> wrote:
> Hi guys,
>
> I'm new in using NHibernate and my only reference is this ebook given to me
> (NHibernate 2.x for beginners).
>
> Now, I'm confused on how to map a many-to-many relationship both on the
> class file and in the mapping file.
>
> I'm not sure what to do or how to map these. I'm thinking of creating
> another class file and mapping file for the ContactPhone table as well as
> it's mapping file.
>
> I really need your help guys.

I'd suggest you try Fluent NHibernate. There's a many-to-many example
in the wiki, it should get you started. Have a look here:
http://wiki.fluentnhibernate.org/Getting_started

In your example I guess it would be something like this:

public class ContactMap : ClassMap<Contact>
{
  public ProductMap()
  {
    Id(x => x.Id);
    Map(x => x.FirstName);
    Map(x => x.LastName);
    Map(x => x.Email);
    HasManyToMany(x => x.PhoneNumbers)
      .ParentKeyColumn("Contact_Id")
      .ChildKeyColumn("Contact_Id")
      .Cascade.All()
      .Table("Contact_Phone");
  }
}

Anyway, check the link. That should get you started.

Good luck!

Daniel

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" 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/nhusers?hl=en.

Reply via email to