I want to use dapper to request dbf files. In my example.dbf file, I have two columns:
- Value - Type NUMERIC
- Name - type CHARACTER
I am writing an ExampleDbf class
class ExampleDbf { public int Value { get; set; } public string Name { get; set; } }
Now I want to write two simple queries
var listOne = connection.Query<ExampleDbf>("SELECT value FROM Example"); var listTwo = connection.Query<ExampleDbf>("SELECT name, value FROM Example");
ListOne is fine, but when I execute listTwo I follow a System.Data.DataException:
Additional information: Error parsing column 0 (name=System.Byte[] - Object)
When I use the standard DataReader, I should write something like this
example.name = System.Text.Encoding.ASCII.GetString((byte[])reader["name"]).Trim();
Of course, I can write something like this:
class ExampleDbf2 { public int Value { get; set; } public byte[] Name { get; set; } public string StringName { get { return System.Text.Encoding.ASCII.GetString((byte[])Name ).Trim(); } } }
So now it works
var listTwo = connection.Query<ExampleDbf2>("SELECT name, value FROM Example");
But this solution is very ugly, maybe someone has a better solution.
source share