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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:46:10+00:00 2026-05-14T06:46:10+00:00

I am using AutoMapper to datareader using code as discussed below http://elegantcode.com/2009/10/16/mapping-from-idatareaderidatarecord-with-automapper/ I see

  • 0

I am using AutoMapper to datareader using code as discussed below
http://elegantcode.com/2009/10/16/mapping-from-idatareaderidatarecord-with-automapper/

I see it being very flakky…and unpredictable.

1) Same code with same datareader at times brings value back to the dto result set and at times doesnot.
2) I have an ID value coming from database as 100, 200. When it maps to the DTO that is of type integer this 100 is changed to a large value (like 234343211).

Any ideas on why am I seeing this inconsitency. Should I be using the standard
while (reader.Read())? and stop using automapper?

  • 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-14T06:46:10+00:00Added an answer on May 14, 2026 at 6:46 am

    I ran into this same problem. It seems to occur when your source type and destination type are not exactly the same.

    In my case, I had a SQL Server table with an ID field that was of type INT. The value was being mapped to a class with a property that was of type long (Int64). This would result in the expected value of 100 getting mapped to something like 668386727769314912. After changing the table schema so that ID is a BIGINT, the values always mapped correctly.

    I would recommend looking closely at the source type and destination type to ensure they are exactly the same. Apparently, conversions that you would expect to work implicitly (like Int32 to Int64) can cause problems.

    Here is an example that will reproduce the problem:

    public class DataMapperIssue
    {
        public class Person
        {
            public long id { get; set; }
            public string first_name { get; set; }
            public string last_name { get; set; }
        }
    
        public static void run()
        {
            var table = new DataTable();
    
            table.Columns.Add("id", typeof(int));
            table.Columns.Add("first_name", typeof(string));
            table.Columns.Add("last_name", typeof(string));
    
            table.Rows.Add(100, "Jeff", "Barnes");
            table.Rows.Add(101, "George", "Costanza");
            table.Rows.Add(102, "Stewie", "Griffin");
            table.Rows.Add(103, "Stan", "Marsh");
            table.Rows.Add(104, "Eric", "Cartman");
    
            AutoMapper.Mapper.Reset();
            AutoMapper.Mapper.CreateMap<IDataReader, Person>();
    
            var results = AutoMapper.Mapper.Map<IDataReader, IList<Person>>(table.CreateDataReader());
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.