Problem with generic type and Equals()


I am creating a OrmLite.IdentityStore project to use AspNet Identity with OrmLite.

Since POCO Id property is a generic type I need to use Equals() to query for this column, but using this I get a NotSupportedException() error in method SqlExpression.VisitColumnAccessMethod(MethodCallExpression m).

This is my code:

return db.Single<TUserToken>(x => x.UserId.Equals(user.Id) && x.LoginProvider == loginProvider && x.Name == name);

I had to change SqlExpression.VisitColumnAccessMethod like this:

SqlExpression.VisitColumnAccessMethod(MethodCallExpression m)
            switch (m.Method.Name)
                case "Equals":
                    statement = $$"{quotedColName}={ConvertToParam(wildcardArg)}";

With this change it works and the generated SQL text is what is expected.
Is this the right solution or am I missing something here?



Except for a few opt-in cases to support common RDBMS functions, there’s generally no support for calling methods on DB Model (i.e. Server) columns and would typically need to use operators in your SQL Expressions.

But I’ve added support for using .Equals() in this commit.

This change is available from v5.2.1 that’s now available on MyGet.


Glad to know that my fix was ok. Didn’t know is there was a better solution.

In my case my UserId column is integer and not string. Maybe the original code works fine with string columns.

I will add support for other functions if needed and create a PR for that.
I will also release the OrmLite.IdentityStore project to GitHub once it’s fully working.
Didn’t find anything so decided to create my own and probably others will need it too.

Thanks again.

1 Like