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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:32:08+00:00 2026-06-15T16:32:08+00:00

I try to map multiple objects to a view model object with ValueInjecter .

  • 0

I try to map multiple objects to a view model object with ValueInjecter. But it does not work as I expect it.

Code:

class Call
{
    public string Number { get; set; }
    public string CustomerNumber { get; set; }
}

class Operation
{
    public int ID { get; set; }
    public string CallNumber { get; set; }
    public string TimeFrom { get; set; }
}

class Customer
{
    public string Number { get; set; }
    public string Name { get; set; }
}

class CallViewModel
{
    public string Number { get; set; }
    public string CustomerName { get; set; }
    public string OperationTimeFrom { get; set; }
}

class Test
{
    static void Main(string[] args)
    {
        var call = new Call { Number = "001337", CustomerNumber = "000001" };
        var op = new Operation { ID = 1, CallNumber = "001337", TimeFrom = "08:00" };
        var customer = new Customer { Number = "000001", Name = "John Doe" };

        var viewModel = new CallViewModel();
        viewModel.InjectFrom(call, op, customer);

        Console.WriteLine("Number:\t\t\t" + viewModel.Number);
        Console.WriteLine("CustomerName:\t\t" + viewModel.CustomerName);
        Console.WriteLine("OperationTimeFrom:\t" + viewModel.OperationTimeFrom);
        Console.ReadLine();
    }
}

Expected Output:

Number:            001337
CustomerName:      John Doe
OperationTimeFrom: 08:00

Effective Output:

Number:            00001
CustomerName:      
OperationTimeFrom: 

Notice

The Call.Number, represented as Number in CallViewModel gets overwritten by Customer.Number. Both CustomerName and OperationTimeFrom never get the value of its designated source Customer.Name and Operation.TimeFrom.

What do I have to do in that scenario? Does ValueInjecter even support this scenario?

  • 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-06-15T16:32:10+00:00Added an answer on June 15, 2026 at 4:32 pm

    I guess you thought of flattening in a different way,
    the way it works is that you go from

    obj.Prop.Prop1.Prop2 to obj.PropProp1Prop2
    

    this is your code modified:

    using System;
    using Omu.ValueInjecter;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            private static void Main(string[] args)
            {
                var call = new Call { Number = "001337", CustomerNumber = "000001" };
                var op = new Operation { ID = 1, CallNumber = "001337", TimeFrom = "08:00" };
                var customer = new Customer { Number = "000001", Name = "John Doe" };
    
                var model = new
                                {
                                    Call = call,
                                    Customer = customer,
                                    Operation = op
                                };
    
                var viewModel = new CallViewModel();
                viewModel.InjectFrom<FlatLoopValueInjection>(model);
    
                Console.WriteLine("Number:\t\t\t" + viewModel.CallNumber);
                Console.WriteLine("CustomerName:\t\t" + viewModel.CustomerName);
                Console.WriteLine("OperationTimeFrom:\t" + viewModel.OperationTimeFrom);
                Console.ReadLine();
            }
    
            class Call
            {
                public string Number { get; set; }
                public string CustomerNumber { get; set; }
            }
    
            class Operation
            {
                public int ID { get; set; }
                public string CallNumber { get; set; }
                public string TimeFrom { get; set; }
            }
    
            class Customer
            {
                public string Number { get; set; }
                public string Name { get; set; }
            }
    
            class CallViewModel
            {
                public string CallNumber { get; set; }
                public string CustomerName { get; set; }
                public string OperationTimeFrom { get; set; }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have added multiple ovals on map view by using below code but I
I have some trouble when I try to map object to int . My
I try create a map for open ~/.vimrc, but open the ~/.vimrc only when
I try to use the following code: ArrayList<String> Map<String, String> Eclipse complains about both
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
Try this piece of code - public class WhitespaceTest { public static void main(String[]
I'm having trouble trying to map my EF 4.1 Code First model to a
I have multiple GroundOverlays loaded on the map and I try to keep them
We know that if we try to access a nonexistent key of std::map with
when I passed a Map<String,String> in velocity template file, and when try to print

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.