paulyoder/LinqToExcel — Issue #8: Mappings of different types, but same property name, conflict.
Author: paqogomez
Created: 2012-02-10 00:42:03+00:00
State: open

Consider these mappings:
instance.AddMapping(x => x.IdentificationName, "Type1 Identification Name");
instance.AddMapping(x => x.IdentificationName, "Type2 Identification Name");

These conflict because the property names are both the same. I believe this could be fixed by modifying the "GetPropertyName" method in ExcelQueryFactory.cs in a manner similar to the following:

private string GetPropertyName(Expression> property)
{
var exp = (LambdaExpression)property;
var type = typeof(TSheetData);

//exp.Body has 2 possible types
//If the property type is native, then exp.Body == typeof(MemberExpression)
//If the property type is not native, then exp.Body == typeof(UnaryExpression) in which
//case we can get the MemberExpression from its Operand property
var mExp = (exp.Body.NodeType == ExpressionType.MemberAccess) ?
(MemberExpression)exp.Body :
(MemberExpression)((UnaryExpression)exp.Body).Operand;
return type + "_" + mExp.Member.Name;
}

Notice that I have added the type to the property name, so the dictionary keys wont confict.
The only other workaround that i've been able to use is to reinstance the ExcelQueryFactory before I map to a different sheet. This however fails when you have transformations that reference other sheets in a relational manner.