Simple select statement not working

Dipping my toes into OrmLite and running some unit tests with the in memory sqlite. These two functions should produce same result.

    public List<TailRegistration> GetByTailnumber(string tailNumber)
    {
        return
            Db.Select<TailRegistration>(
                x => x.TailNumber == tailNumber);
    }

    public List<TailRegistration> GetByTailnumber2(string tailNumber)
    {
        return
            Db.Select<TailRegistration>(
                x => x.TailNumber.Equals(tailNumber));
    }

The second function does not work and gives me a “NotSupportedException”. Not sure why .equals doesn’t work. Both sides are strings.

Test method KioskApp.Data.Tests.TailRegistrationsRepositoryTests.GetByTailnumberTest2 threw exception: 

System.NotSupportedException: Specified method is not supported.
at ServiceStack.OrmLite.SqlExpression1.VisitColumnAccessMethod(MethodCallExpression m) at ServiceStack.OrmLite.Sqlite.SqliteExpression1.VisitColumnAccessMethod(MethodCallExpression m)
at ServiceStack.OrmLite.SqlExpression1.VisitMethodCall(MethodCallExpression m) at ServiceStack.OrmLite.SqlExpression1.Visit(Expression exp)
at ServiceStack.OrmLite.SqlExpression1.VisitLambda(LambdaExpression lambda) at ServiceStack.OrmLite.SqlExpression1.Visit(Expression exp)
at ServiceStack.OrmLite.SqlExpression1.AppendToWhere(String condition, Expression predicate) at ServiceStack.OrmLite.SqlExpression1.Where(Expression1 predicate) at ServiceStack.OrmLite.ReadExpressionCommandExtensions.Select[T](IDbCommand dbCmd, Expression1 predicate)
at ServiceStack.OrmLite.OrmLiteReadExpressionsApi.<>c__DisplayClass14_01.<Select>b__0(IDbCommand dbCmd) at ServiceStack.OrmLite.OrmLiteExecFilter.Exec[T](IDbConnection dbConn, Func2 filter)
at ServiceStack.OrmLite.OrmLiteReadExpressionsApi.Exec[T](IDbConnection dbConn, Func2 filter) at ServiceStack.OrmLite.OrmLiteReadExpressionsApi.Select[T](IDbConnection dbConn, Expression1 predicate)
at KioskApp.Data.TailRegistrationsRepository.GetByTailnumber2(String tailNumber) in C:\git\airport-kiosk\KioskApp.Data\TailRegistrationsRepository.cs:line 42
at KioskApp.Data.Tests.TailRegistrationsRepositoryTests.GetByTailnumberTest2() in C:\git\airport-kiosk\Test.KioskApp\TailRegistrationsRepositoryTests.cs:line 167

Each C# Expression needs to be parsed, converted to SQL and executed on the server. The == operator is parsed and translated to = in SQL, the .Equals() is a virtual method call which in C# could could be overloaded in classes which doesn’t have an equivalent in SQL.

Just use the == for expressions you want converted to = in server-side SQL.

Got it. Thanks for the quick reply!

Note that the EV will nicely convert some methods (Contains / EndsWith / StartsWith) to SQL % wildcards!

Very handy.