Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4340872
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:24:29+00:00 2026-05-21T11:24:29+00:00

Hi I’m struggling do refine/refactoring a domain model and trying to move logic from

  • 0

Hi I’m struggling do refine/refactoring a domain model and trying to move logic from application services into my domain model. Now I’m stuck with a NHibernate issue.

The model is a WorkEvaluation class that contains a Questionaire Template with Questions and it also contains a collection of QuestionWeight classes. The thing is that WorkEvaluation class also has an important property HitInterval that belongs closed to the QuestionWeight collection in WorkEvaluation. The concept is that you conduct an evaluation by answering a lot of questions (the anserws are excluded in this example) and finaly you apply some weights (percent weights) that modify answer scores. That means you can make some questions more important and other less important. Hit interval is also a tuning parameter that you use when you calculate TOTAL WorkEvaluation score (including weight modifications) and the result is for example: Totalscore = 100, Hitinterval 5% than we get a totalinterval of 95-105 and can be used to match other evaluations.

Enough of background.
I Want to encapsulate both list of QuestionWeights and HitInterval in a Value Object QuestionScoreTuning since these belongs together and should be applied at the same time.
And I also want to add some business logic into QuestionScoreTuning that do not belongs to workEvaluation.
How do I map i Fluent Nhibernate a Value Object (Component) that has the one-to-many collection and HitInterval and the reference back? This is my current code:

public class WorkEvaluation : DomainBase<long>, IAggregateRoot
{
 public void ApplyTuning(QuestionScoreTuning tuning)
        {
            QuestionScoreTuning = tuning;
            //TODO Raise Domain Event WorkEvaluationCompleted - 
            // which should recalculate all group scores
        }
 public QuestionScoreTuning QuestionScoreTuning { get; protected set; }
}

public class QuestionScoreTuning : ValueObject
    {
        private IList<QuestionWeight> _questionWeights;

        public QuestionScoreTuning(IList<QuestionWeight> listOfWeights, long hitInterval)
        {
            _questionWeights = listOfWeights;
            HitInterval = hitInterval;
        }

        public long HitInterval { get; protected set; }

        protected override IEnumerable<object> GetAtomicValues()
        {
            return _questionWeights.Cast<object>();
        }

        /// <summary>
        /// A list of all added QuestionWeights for this WorkEvaluation
        /// </summary>
        public IList<QuestionWeight> QuestionWeights
        {
            get { return new List<QuestionWeight>(_questionWeights); }
            protected set { _questionWeights = value; }
        }

        protected QuestionScoreTuning()
        {}
    }

public class QuestionWeight : DomainBase<long>, IAggregateRoot
{
    public QuestionWeight(Question question, WorkEvaluation evaluation)
    {
        Question = question;
        WorkEvaluation = evaluation;
    }

    public Weight Weight { get; set; }
    public Question Question { get; protected set; }
    public WorkEvaluation WorkEvaluation { get; protected set; }

    public override int GetHashCode()
    {
        return (Question.GetHashCode() + "|" + Weight).GetHashCode();
    }

    protected QuestionWeight()
    {}
}

Fluent Mappings:

public class WorkEvaluationMapping : ClassMap<WorkEvaluation>
    {
        public WorkEvaluationMapping()
        {
            Id(x => x.ID).GeneratedBy.Identity();
            References(x => x.SalaryReview).Not.Nullable();
            References(x => x.WorkEvaluationTemplate).Column("WorkEvaluationTemplate_Id").Not.Nullable();
            Component(x => x.QuestionScoreTuning, m =>
                                                      {
                                                          m.Map(x => x.HitInterval, "HitInterval");
                                                          m.HasMany(x => x.QuestionWeights).KeyColumn("WorkEvaluation_id").Cascade.All();
                                                      });

            }
    }

public class QuestionWeightMapping : ClassMap<QuestionWeight>
    {
        public QuestionWeightMapping()
        {
            Not.LazyLoad();
            Id(x => x.ID).GeneratedBy.Identity();
            Component(x => x.Weight, m =>
                                         {
                                             m.Map(x => x.Value, "WeightValue");
                                             m.Map(x => x.TypeOfWeight, "WeightType");
                                         });
            References(x => x.Question).Column("Question_id").Not.Nullable().UniqueKey(
                "One_Weight_Per_Question_And_WorkEvaluation");
            References(x => x.WorkEvaluation).Column("WorkEvaluation_id").Not.Nullable().UniqueKey(
                "One_Weight_Per_Question_And_WorkEvaluation");
        }
    }

All I want to accomplish is to move collection of QuestionWeights and HitInterval into a Value Object (Component mapping) since these will still be inside db table WorkEvaluation.

P.S I’ve look at some example solution DDDSample.net (Eric Evans DDD example in c#) and they accomplished this with the Itinerary class that takes a list as ctor parameter and is mapped as a Cargo component. Difference is that example has a list of valueobjects Leg BUT Leg has references to Location which is an entity class.

Hopefully maybe someone knows how to accomplish this. Thanks in advance…
/Bacce

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T11:24:30+00:00Added an answer on May 21, 2026 at 11:24 am

    Well. I Finally solved it. Now my WorkEvaluation object can be Applied with a QuestionScoreTuning object (a valueobject) that contains the list of weight and hitinterval. This turns out great and if anyone want more info about having collections inside value objects and mapping them in fluent NH, please ask here with a comment. I can supply code examples…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.