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

  • SEARCH
  • Home
  • 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 8993581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:13:23+00:00 2026-06-15T23:13:23+00:00

I have linQ query like the one below var records = (from P in

  • 0

I have linQ query like the one below

 var records = (from P in Person
                join B in BankAccount
                on P.ID equals B.PersonID
                select new { P, B}).ToList();

The person table has a lot of fields but I need to only work with ID & Name. Similarly for BankAccount I only need to work with ID, AccountType and AccountBalance

I then pass the records var type as above to another mapper class with a method like so

    public List<CompositeDTO> MapToDto(IEnumerable<object> data)
    {
        foreach (var rec in data) 
        {
         dto.InjectFrom(rec );
         dtoList.Add(dto);
        }
        return dtoList;
    }

Where CompositeDTO is as below

public class CompositeDTO 
{
  public int PersonID {get; set;}
  public String PersonName {get; set;}
  public int AccountID {get; set;}
  public String AccountType{get; set;}
  public int AccountBalance{get; set;}
}

The problem is I am not able to get any values into my object of type CompositeDTO using dto.InjectFrom(rec )

How should this be done? The documentation here only explained how to do it for one field from two different source classes. Have I missed something ? Can this be done?

  • 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-15T23:13:25+00:00Added an answer on June 15, 2026 at 11:13 pm

    I think AutoMapper does the job better here. I modified the map method using AutoMapper as below and it worked

    public List<CompositeDTO> MapToDto(IEnumerable<object> data)
    {
         dtoList = data.Select(Mapper.DynamicMap<CompositeDTO>).ToList();
    
        //foreach (var rec in data) 
        //{
        // dto.InjectFrom(rec );
        // dtoList.Add(dto);
        //}
        return dtoList;
    }
    

    All I needed to do was add the alias I used in the linQ query to the CompositeDTO‘s property like so P_PersonID and B_AccountType

    I think ValueInjecter should work on adding this feature. I really like not having to create a map before I use it like how it is done in AutoMapper currently for non-dynamic types. I am now using two different object mappers in my code. Is that bad?

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

Sidebar

Related Questions

Let's say I have a linq query like the one below var LinqResult =
I have a Linq to Entities query like this one: var results = from
If you have a simple Linq query like: var result = from record in
I have a Linq query that looks something like this: var myPosse = from
I have a Linq query that looks something like this: var query = from
I have a complex LINQ query like var results = from obj1 in context.ProcessBases
I have a LINQ query that is currently like this: var query = from
I have a linq query var x = (from t in types select t).GroupBy(g
I have a LINQ query that returns some object like this... var query =
I have a LINQ query to a DataTable : var list = from row

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.