0

I have a composite object set up Project->Appraisal, My appraisal object has a ApprovedMentor object which is not required but when i go to save project Nhib throws and error to say that ApprovedUser has not been set. but its not set because its not a required field. How do i set up this using fluent auto mapping, is it possible?

 public class MentoringProject : BaseEntity
{
    public MentoringProject()
    {
        Appraisal =  new Appraisal();

    }

        [NotNullNotEmpty]
        [Length(Min=25, Max=1000)]
        public virtual string Description { get; set; }

        [Length(Min=25, Max=1000)]
        public virtual string SupportRequired { get; set; }

        [NotNullNotEmpty]
        public virtual System.DateTime? DateSubmitted { get; set; }

        [NotNullNotEmpty]
        public virtual System.DateTime? ClosingDate { get; set; }

        [NotNullNotEmpty]
        [Size(Min=1)]
        public virtual short Duration { get; set; }

        [NotNullNotEmpty]
        public virtual string Skills { get; set; }


        public virtual Appraisal Appraisal { get; set; }

}

 public class Appraisal : BaseEntity
{
    public Appraisal()
    {
        ShortlistedMentors = new List<User>();
        ApprovedMentor =  new User();
        College =  new RefData();
    }

    #region Primitive Properties

    public virtual bool Decision { get; set; }

    public virtual System.DateTime? ApprovedDate { get; set; }

    public virtual System.DateTime? AcceptedDate { get; set; }

    public virtual System.DateTime? CompletionTargetDate { get; set; }

    public virtual string RejectionReason { get; set; }

    #endregion

    #region Navigation Properties

    public virtual IList<User> ShortlistedMentors { get; set; }

    public virtual User ApprovedMentor { get; set; }

    public virtual RefData College { get; set; }

    #endregion
}
Simon
  • 415
  • 1
  • 4
  • 15
  • Is User class an entity? – Vadim Jan 05 '11 at 01:48
  • Yes, its is. I attach it to various object within the domain model, like MentoringProject.AddedUser, MentoringProject.UpdatedUser, the ShortlistedMentors is also a collection of User object, I was thinking i should just make sure ApprovedUser is set to null when I call save? – Simon Jan 05 '11 at 07:34

2 Answers2

0

It looks to me that you just want to ignore the ShortlistedMentors property which you need to do in your mapping class like this:

map.IgnoreProperty(p => p.ShortlistedMentors);

This answer was posted in this question.

Community
  • 1
  • 1
Vasile Laur
  • 699
  • 7
  • 16
  • The property that I want to set optionally is ApprovedMentor, the user will not set this initially when the object is saved, but is should be saved at some point after the initial saved. – Simon Jan 05 '11 at 07:34
0

I think i have solved this, when binding the UI to the controller in MVC, MVC creates an empty User object and because that object has required fields set on it using nhib validator and nhib was trying to create a new user object, I got round this by checking if there is a user realtionship to add, if not I set the Appraisal.ApprovedMentor==null

Simon
  • 415
  • 1
  • 4
  • 15