views:

203

answers:

1

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

A: 

What type is the NickName property? Is it a string too? From the fullname (MySite.Domain.DomainModel.EntityFramework.NickName) it looks like it is the name of a domain class.

Maybe the left expression is not resolving to the NickName property in your class?

What is "this._KeyProperty"? is it the same as the KeyProperty you set to columnName?

Juan Tarquino