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
c # automapper


source to share


No one has answered this question yet

Check out similar questions:

1758
How do I generate a random int?
817
decimal and double! - Who should I use and when?
636
Convert decimal to double
128
Converting a string to a nullable type (int, double, etc.)
sixteen
AutoMapper: how to parse Int from string and possibly create rules based on data type?
4
Automapper: convert int to string
3
AutoMapper TypeConverter not getting called when mapping IDataReader
0
Set up property mapping from destination to source and reverse map
0
Zero foreign key code in Entity Framework first
0
Make AutoMapper automatically display prefix properties



All Articles
Loading...
X
Show
Funny
Dev
Pics