Results 1 to 2 of 2

Thread: nHibernate 3.2 - Mapping in Code - ManyToMany

  1. #1

    Thread Starter
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    nHibernate 3.2 - Mapping in Code - ManyToMany

    Hi,
    [Not sure where to post, since it's an nHibernate Question]
    I'm stuck using the newer build in mapping by code with nHibernate in a many to many relationship between my User and Role objects (each got an Id member and an IList<T> of the other)
    My mapping class (for user) look as follows:
    Code:
    public UserMap()
    {
        Table("Users");
        Property(x => x.UserName);
        ....
        Bag(u => u.Roles,
            map =>
                {
                    //map.Access(Accessor.Field);
                    map.Table("Users_Roles");
                    map.Cascade(Cascade.All);
                    map.Key(k => k.Column("UserId"));
                    map.Inverse(true);
                },
                u => u.ManyToMany(x => x.Column("RoleId")));
    Like that it gives me an error:
    "An association from the table Users_Roles refers to an unmapped class"
    If I uncomment the line map.Access(Accessor.Field); it tells me:
    "Could not compile the mapping document: mapping_by_code"

    Anyone know this mapping by code well (I'm not talking about FluentNHibernate and not using xml mapping)


  2. #2

    Thread Starter
    Hyperactive Member Krokonoster's Avatar
    Join Date
    Jan 2010
    Location
    Cape Town
    Posts
    448

    Re: nHibernate 3.2 - Mapping in Code - ManyToMany

    Solved it. Problem was in my configuration. (stupid one)
    Code:
    // duuuh!!!
    //mapper.AddMapping<UserMap>();
    // should be this....
    mapper.AddMappings(Assembly.GetAssembly(typeof(UserMap)).GetExportedTypes());


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width