jonwagner / Insight.Database

Fast, lightweight .NET micro-ORM

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Blocking automatic mapping to allow post-processing

lmnash opened this issue · comments

Type

[] Bug report.
[x ] Feature request.

Current Behavior

I have a list of string values stored in a database in a varchar column as a semi-colon separated list. The type in the class that needs to be returned is a string array. I can't modify the database table structure or the return class.

I need to tell Insight how to map this string to a string array.

I have tried to implement a PostProcessRecordReader, but unfortunately the column name and the object property name match and Insight is trying to map them and throwing an error before it gets to post processing.

The error is:

System.InvalidOperationException: Field DropAttachmentsExtensions cannot be converted from System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 to System.String[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. Create a conversion constructor or conversion operator.
at Insight.Database.CodeGenerator.TypeConverterGenerator.EmitConvertValue(ILGenerator il, String memberName, Type sourceType, Type targetType, IDbObjectSerializer serializer) in c:\projects.net\Insight.Database\Insight.Database\CodeGenerator\TypeConverterGenerator.cs:line 170

I have tried using a OneToOne inside the PostProcessRecordReader to stop the mapping of the column by mapping it to a non-existent property but this isn't working, it appears if the custom column mapping points to a property that doesn't exist it returns to the default mapping.

I would prefer to avoid using a custom reader because this table and class contains 41 columns / properties and the others all map correctly.

Is my only option modifying the stored procedure to specify all the column names (it currently uses SELECT *) and then alias the column name, or is there some way to tell Insight NOT to map a specific column \ property, or tell it how to map string to string[] in this specific case before the error occurs.

Expected behavior

I am able to somehow tell Insight not to map that column in order to allow the post processing to set the value.

Steps to Reproduce

Create a varchar database column and query it using a return type with a string array property of the same name.

Any other comment

I think a Column Mapper might be useful on this scenario.

Yes, you should be able to install a custom column mapper to exclude that column.

great, I'll give that a go, thanks