1

Resolved

System.ArgumentException in TableColumn(FieldAttribute definition, PropertyInfo pi)

description

System.ArgumentException was unhandled by user code
Message=Object of type 'System.Double' cannot be converted to type 'System.Decimal'.
Source=mscorlib
StackTrace:
   at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)
   at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
   at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
   at System.Reflection.RuntimePropertyInfo.SetValue(Object obj, Object value, Object[] index)
   at SqliteORM.TableColumn.<.ctor>b__1(TableColumn tc, Object inst, Object val) in C:\svn\sqliteorm\SqliteORM\TableColumn.cs:line 61
   at SqliteORM.TableColumn.SetValue(Object inst, Object val) in C:\svn\sqliteorm\SqliteORM\TableColumn.cs:line 97
   at SqliteORM.Query`1.ReadRow(IDataRecord reader, TableMeta meta) in C:\svn\sqliteorm\SqliteORM\Query.cs:line 128
   at SqliteORM.Query`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>d__3.MoveNext() in C:\svn\sqliteorm\SqliteORM\Query.cs:line 91
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
 
 
 
Test code:
 
[TestClass]
public class TableColumnTest
{
    [Table]
    public class TestDecimalClass
    {
        [PrimaryKey]
        public string Key { get; set; }
 
        [Field]
        public decimal DecimalField { get; set; }
    }
 
    [TestMethod]
    public void TableColumnConstructorTest()
    {
        DbConnection.Initialise("Data Source=test.db3");
 
        using (TableAdapter<TestDecimalClass> adapter = TableAdapter<TestDecimalClass>.Open())
        {
            adapter.CreateUpdate(new TestDecimalClass {Key = "1", DecimalField = 0});
            TestDecimalClass t = adapter.Select().Where(c => c.Key == "1").SingleOrDefault();
            if (t==null)
                Assert.Fail("adapter.Select().Where(c => c.Key == \"1\").SingleOrDefault()   return null");
            else
                Assert.AreEqual(0, t.DecimalField);
 
        }
    }
}
 
 
 
to fix, you must add the code
 
 
if (Type == typeof (decimal))
     Set = (tc, inst, val) => _propertyInfo.SetValue (inst, Convert.ToDecimal (val), null);
 
at the end of the constructor TableColumn (FieldAttribute definition, PropertyInfo pi)

file attachments

comments

DarkStranger wrote Aug 3, 2012 at 10:12 PM

Fixed. Thanks for catching the bug and posting a solution!

wrote Aug 3, 2012 at 10:14 PM

wrote Feb 14, 2013 at 2:31 AM

asavasamuel wrote Mar 8, 2013 at 6:19 AM

Darkstranger

Here is an ORM that works with Sqlite
https://www.kellermansoftware.com/p-47-net-data-access-layer.aspx

wrote May 16, 2013 at 8:17 AM

wrote May 16, 2013 at 8:17 AM

wrote Jun 14, 2013 at 6:59 AM