Double convert to large when matching against an int column

I am using AutoMapper

to match strings of data in class objects. One of the data columns is of type double, the equivalent property of which in the class is of type int:

DataTable source = new DataTable();
source.Columns.Add("ProductId", typeof(double));
source.Columns.Add("Code", typeof(string));
source.Columns.Add("Name", typeof(string));
source.Columns.Add("Description", typeof(string));
source.Columns.Add("Price", typeof(double));

      

ProductId

is double of datatable and int in the class:

public class Products
{
    public Int32 ProductId { get; set; }
    public String Code { get; set; }
    public String Name { get; set; }
    public String Description { get; set; }
    public float Price { get; set; }
}

      

I am matching them along these lines:

Mapper.CreateMap<IDataReader, IEnumerable<Products>>();
IEnumerable<Products> products = Mapper.DynamicMap<IDataReader, IEnumerable<Products>>(source.CreateDataReader());

      

When matching is done, for example the following line:

DataRow row = source.NewRow();
row[0] = 1.0;
row[1] = "Code";
row[2] = "Name";
row[3] = "Description";
row[4] = 4.75;
source.Rows.Add(row);

      

the result will be:

Code: "Code"
Description: "Description"
Name: "Name"
Price: 4.75
ProductId: 5102336

      

I tried adding a value converter as follows, but nothing changed.

Mapper.CreateMap<double, int>().ConvertUsing(Convert.ToInt32);

      

Is this a problem between AutoMapper and IDataReader to convert double to int?

+3


source to share





All Articles