|
-
Jul 9th, 2012, 03:59 AM
#1
Thread Starter
Hyperactive Member
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)
-
Jul 9th, 2012, 05:01 AM
#2
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|