Uri Hendler - 81 - Jul 9, 2014

+Demis Bellot 
A question on OrmLite’s support for auto mapping {Table}{Field} convention.

From looking at the code, it’s matching on the FieldDefinition.FieldName property (i.e. actual, possibly aliased, column name) instead of the FieldDefinition.Name property:

// Add support for auto mapping {Table}{Field} convention
foreach (var tableDef in tableDefs)
    var tableName = tableDef.Name;
    var matchingField = tableDef.FieldDefinitionsArray
        .FirstOrDefault(x => tableName + x.FieldName == fieldDef.Name);


This means it won’t work in some cases e.g. if the columns have aliases containing a space.

public class User 
    public property Id { get; set; }
    [Alias(“First Name”)]
    public property Name { get; set; }
    [Alias(“Last Name”)]
    public property Surname { get; set; }

POCO for join result:
public class UserDetail
    public property UserId { get; set; }
    public property UserName { get; set; }
    public property UserSurname { get; set; }

The convention will look for “User” + “First Name” == “UserName” and not find a match.

Was this your intended design?
Or should the code be changed to:
var matchingField = tableDef.FieldDefinitionsArray
    .FirstOrDefault(x => tableName + x.Name == fieldDef.Name);

ok yeah that should be just the Property Names. I’ve updated it in this commit to also include Alias property names:

Which is now on MyGet: