brucezhang80 / dapper-dot-net

Automatically exported from code.google.com/p/dapper-dot-net
Other
0 stars 0 forks source link

Error parsing column 10 (RTP_FLAG=True - Boolean) #36

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.return conn.Query<RecordModel,RecordTypeModel,RecordModel>(
                    "SELECT RCD_ID,RCD_RTP_ID,RCD_DT,CRD_TITLE,RCD_AMOUNT,RCD_PLACE,RCD_MEMO,RCD_TYPE,RTP_ID,RTP_NAME,RTP_FLAG FROM BRECORD A LEFT JOIN RRECORDTYPE B ON A.RCD_RTP_ID = B.RTP_ID ORDER BY A.RCD_ID  ",
                    (record, type)
                        =>
                    {
                        record.TYPE = type;
                        return record;
                    },splitOn:"RTP_ID")
                    .ToList<RecordModel>();

2.public static void ThrowDataException(Exception ex, int index, IDataReader 
reader)
        {
            string name = "(n/a)", value = "(n/a)";
            if (reader != null && index >= 0 && index < reader.FieldCount)
            {
                name = reader.GetName(index);
                object val = reader.GetValue(index);
                if (val == null || val is DBNull)
                {
                    value = "<null>";
                }
                else
                {
                    value = Convert.ToString(val) + " - " + Type.GetTypeCode(val.GetType());
                }
            }
            throw new DataException(string.Format("Error parsing column {0} ({1}={2})", index, name, value), ex);-----throw DataException
        }

What is the expected output? What do you see instead?

 System.InvalidCastException: Error parsing column 10 (RTP_FLAG=True - Boolean)
----------------------------------------
Please help me,Thanks!

Original issue reported on code.google.com by hui.chen...@gmail.com on 16 Jun 2011 at 11:56

GoogleCodeExporter commented 9 years ago
What data-type is RTP_FLAG in the database, and what data-type is the property?

Original comment by marc.gravell on 16 Jun 2011 at 12:09

GoogleCodeExporter commented 9 years ago
I'm so sorry,The data-type in the database is bit,but the data-type in the 
model class is int. 
Thank you again!

Original comment by hui.chen...@gmail.com on 17 Jun 2011 at 3:56

GoogleCodeExporter commented 9 years ago
Dapper tries to map *very* directly, to avoid having to compensate in 27 
directions. If the data is a bit in the database, it should be a `bool` in your 
code. That will also have the positive effect that you can't use values in your 
model that can't be stored.

Original comment by marc.gravell on 17 Jun 2011 at 5:07

GoogleCodeExporter commented 9 years ago
this is by-design. Dapper expects the data types in the model to match 
*exactly* to the data types in the DB

Original comment by sam.saff...@gmail.com on 11 Jul 2011 at 11:31