c# - One-To-Many mapping fluent NHibernate -


i trying one-to-many relation working. have following mappings:

    public class user {      public user()     {         usercourses = new list<usercourse>();     }      public virtual int id { get; private set; }      public virtual ilist<usercourse> usercourses { get; private set;}   }     public sealed class usermap : classmap<user> {     public usermap()     {         id(x => x.id, "id");          hasmany(x => x.usercourses).inverse().cascade.all().table("usercourse");          table("[user]");     } }     public sealed class usercoursemap : classmap<usercourse> {     public usercoursemap()     {         id(x => x.id, "id");          references(x => x.user, "userid");          map(x => x.role, "role");     } } 

i getting following exception if try make instance of user object , tries view courses:

                var user = (from u in userrepository.linq() // fetch user                         u.username == username                         select u).single();              var courses = user.usercourses.single(); // wont work 

{"invalid column name 'user_id'.\r\ninvalid column name 'user_id'."} not initialize collection: [fringedivision.rapp.domain.user.usercourses#1][sql: select usercourse0_.user_id user4_1_, usercourse0_.id id1_, usercourse0_.id id1_0_, usercourse0_.role role1_0_, usercourse0_.userid userid1_0_ [usercourse] usercourse0_ usercourse0_.user_id=?]

i can't seem understand problem is, suggestions? reference mappings seems work if make instance of usercourse object.

add column has many

hasmany(x => x.usercourses).keycolumn("userid") or whatever actualy syntax in version of fnh on


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

android - layout with fragment and framelayout replaced by another fragment and framelayout -