Skip to content

Ability to use .Query<T> on a table where column names contain reserved characters #318

Description

@simonmckenzie

The .Query<TModel>() method maps column names to property names on the model, but this means that if a column name contains characters that can't be in a c# property (e.g. % or (), we can't use it.

It would be good if an attribute called something like ColumnNameAttribute were added to the project so we could use it to annotate properties in the model, which would allow us to map columns with unusual characters easily.

A model would look something like this:

public class RowModel
{
    [ColumnName("Coverage %")]
    public string Coverage {get; set; }

    // etc.
}

I imagine the code would use the value in this attribute, falling back to the property name if the attribute isn't present. It'd be a small change here:

foreach (var propertyName in RowMaterializer.GetSettableProperties(typeof(T))
.Select(property => property.Name))

I've seen this pattern used in other data mapping-type libraries, and it works well, e.g. https://github.com/hughbe/excel-mapper#attribute-based-mapping

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions