NHibernate Collection Sub Query

后端 未结 3 1337
半阙折子戏
半阙折子戏 2021-01-21 14:51

Is there a way to add criteria to a mapping for NHibernate?

public class Course {
   public IList Participants { get; set; }
   public IList&l         


        
3条回答
  •  遥遥无期
    2021-01-21 15:06

    If you have subclasses of Participant with the status being the DiscriminatorValue, I think you can have them as separate lists since this way nHibernate knows how to differentiate them.

    public class ParticipantMap : ClassMap
    {
        public ParticipantMap()
        {
            DiscriminateSubClassesOnColumn("Status");
        }
    }
    public class ActiveParticipantMap : SubclassMap
    {
        public ActiveParticipantMap ()
        {
            DiscriminatorValue("Active");
        }
    }
    // other subclasses of participant e.g. NonActive, etc.
    
    public class Course {
        public IList Participants {get;set;}
        public IList ActiveParticipants {get;set;}
        // any other lists of participant subclasses that you may have
    }
    

提交回复
热议问题