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 7437835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:27:37+00:00 2026-05-29T10:27:37+00:00

I am need help mapping my Domain Object to a ViewModel for use with

  • 0

I am need help mapping my Domain Object to a ViewModel for use with my C#/MVC App

In the FormAnswer Class there can only be 1 Answer Type (AnswerCurrency, AnswerDateTime, AnswerBool,etc) this is enforced in the Database and Application Logic.

If a Answer exists it will needs to be to Mapped to the Answer Property in the FormAnswerModel if all values are null the Answer is a Empty String.

public class FormQuestion
{
   public int Id {get; set;)
   public string DataType {get; set;} 
   public string Question {get; set;} 
}

public class FormAnswer
{
   public int Id {get; set;)
   public int QuestionId {get; set;)
   public double? AnswerCurrency {get;set}
   public dateTime? AnswerDataTime {get;set}
   public bool? AnswerBool {get;set}
   public string AnswerString{get;set}
   public string AnswerText{get;set}
}

public class FormAnswerModel
{
   public int Id {get; set;)
   public int QuestionId {get; set;)
   public string Answer{get;set}
}
  • 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-29T10:27:38+00:00Added an answer on May 29, 2026 at 10:27 am

    ValueResolver is a good suggestion, especially if you have this pattern elsewhere. If you’re looking for a quick and dirty version (that is, if this is the only place you need to handle this sort of situation), try this:

    Mapper.CreateMap<FormAnswer, FormAnswerModel>()
        .ForMember(d => d.Answer, o => o.ResolveUsing(fa =>
            {
                string answer = String.Empty;
                if (fa.AnswerBool.HasValue)
                {
                    return fa.AnswerBool.Value;
                }
    
                if(fa.AnswerCurrency.HasValue)
                {
                    return fa.AnswerCurrency.Value;
                }
    
                if(fa.AnswerDateTime.HasValue)
                {
                    return fa.AnswerDateTime;
                }
    
                if(!String.IsNullOrEmpty(fa.AnswerString))
                {
                    return fa.AnswerString;
                }
    
                return answer;
            }
        ));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need help understanding some C++ operator overload statements. The class is declared like
I need help with the best practice to localize asp mvc apps, I saw
I have an ASP.NET MVC web app whose controllers use WCF to call into
I am new to LINQ to XML and need help in mapping an XML
I use RestKit with Object-mapping. This runs asyncronus and after receiving the Data from
Can this ever make sense? Say I need to fetch an object from the
I need a mapping service that will show an aerial view that can be
need help to create regular expression matching string www.*.abc.*/somestring Here * is wild card
Need help writing a script downloads data from google insight using c# this is
I need help on this following aspx code aspx Code: <asp:Label ID =lblName runat

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.