-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: How do you make non foriegn key constraints in nhibernae?
PostPosted: Tue May 10, 2011 1:29 pm 
Newbie

Joined: Sat May 07, 2011 2:19 pm
Posts: 3
Hi

I am using fluent nhibernate(v1.2) and nhibernate(v3.1) and I am having a weird Problem.

I have this
Code:
          public class GradeMap : ClassMap<Grade>
    {
        public GradeMap()
        {
            Id(x => x.GradeId);
            Map(x => x.TaskName).NvarcharWithMaxSize().Not.Nullable();
            Map(x => x.Weight).Not.Nullable().Precision(5).Scale(2);
            Map(x => x.OutOf).Not.Nullable().Precision(5).Scale(2);
            Map(x => x.Mark).Not.Nullable().Precision(5).Scale(2);
            Map(x => x.CourseBackgroundColor).Not.Nullable();
            Map(x => x.CoursePrefix).Not.Nullable();
            References(x => x.Student).Not.Nullable();
            References(x => x.Course);
        }
    }

    public class CourseMap : ClassMap<Course>
    {
        public CourseMap()
        {
     
            Id(x => x.Id).Column("CourseId");
            Map(x => x.Prefix).NvarcharWithMaxSize().Not.Nullable();
            HasMany(x => x.Tasks).Cascade.Delete().Inverse();
            HasMany(x => x.CoursePermissions).Cascade.All().Inverse();
            HasMany(x => x.CourseSharing).Cascade.All().Inverse();
            HasMany(x => x.Grades).Cascade.None().Inverse();
        }
    }



I then do something like this
Code:
    return session.Query<Grade>().ToList();



If I would try to grab a propety such as `Grade.Course.Id` it would crash and I would get.

Code:
    Grade.Course = {Castle.Proxies.CourseProxy}
    Grade.Course.Id = '((new System.Collections.Generic.Mscorlib_CollectionDebugView<OnlGrade>(grades)).Items[0].Course).Id' threw an exception of type 'NHibernate.ObjectNotFoundException'
    Grade.Course.Prefix = above error except .Prefix instead of .Id


I would have thought Course Object would be empty or null. Not that it would have some Proxy with all properties throwing exceptions.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.