I have a generic SelectAllByKey method in my repository:
public IList<E> SelectAllByKey(string columnName, string key)
{
KeyProperty = columnName;
Expression rightExpr = null;
rightExpr = Expression.Constant(key);
// First we define the parameter that we are going to use the clause.
var xParam = Expression.Parameter(typeof(E), typeof(E).Name);
MemberExpression leftExpr = MemberExpression.Property(xParam, this._KeyProperty);
BinaryExpression binaryExpr = MemberExpression.Equal(leftExpr, rightExpr);
... The method continues on from there but the rest isn't important because the last line there is the one it crashes on.
When I run these parameters through there:
columnName: "NickName", key: "Matt"
I get this error:
"The binary operator Equal is not defined for the types 'MySite.Domain.DomainModel.EntityFramework.NickName' and 'System.String'."
What am I missing here that's making it not work... Any ideas?
Thanks,
Matt