Permalink
Browse files

Don't escape wildcards in .Equals() expression

  • Loading branch information...
mythz committed Dec 6, 2018
1 parent ae9f8f2 commit 7c7fbc81c5022b6b3ff397bd86bf0dc34aacf016
@@ -2713,7 +2713,7 @@ protected virtual object VisitColumnAccessMethod(MethodCallExpression m)
: null;
statement = converter != null
? $"{quotedColName}={ConvertToParam(converter.ToDbValue(argType, arg))}"
: $"{quotedColName}={ConvertToParam(wildcardArg)}";
: $"{quotedColName}={ConvertToParam(arg)}";
break;
case "StartsWith":
statement = !OrmLiteConfig.StripUpperInLike
@@ -1,4 +1,5 @@
using NUnit.Framework;
using ServiceStack.DataAnnotations;

namespace ServiceStack.OrmLite.Tests.Expression
{
@@ -201,8 +202,7 @@ public void Can_select_using_Equals()
{
var postfix = "postfix";

var expected = new TestType()
{
var expected = new TestType {
IntColumn = 7,
BoolColumn = true,
StringColumn = postfix
@@ -214,9 +214,9 @@ public void Can_select_using_Equals()
{
var actual = db.Select<TestType>(q => q.StringColumn.Equals(postfix));

Assert.IsNotNull(actual);
Assert.AreEqual(1, actual.Count);
CollectionAssert.Contains(actual, expected);
Assert.That(actual, Is.Not.Null);
Assert.That(actual.Count, Is.EqualTo(1));
Assert.That(actual, Is.EquivalentTo(new[]{ expected }));
}
}

@@ -0,0 +1,32 @@
using NUnit.Framework;
using ServiceStack.DataAnnotations;

namespace ServiceStack.OrmLite.Tests.Issues
{
public class SqlExpressionIssues : OrmLiteTestBase
{
public class MetadataEntity
{
[AutoIncrement]
public int Id { get; set; }
public int ObjectTypeCode { get; set; }
public string LogicalName { get; set; }
}

[Test]
public void Can_Equals_method_and_operator_with_Scalar()
{
OrmLiteUtils.PrintSql();

using (var db = OpenDbConnection())
{
db.DropAndCreateTable<MetadataEntity>();

db.Insert(new MetadataEntity {ObjectTypeCode = 1, LogicalName = "inno_subject"});

Assert.That(db.Scalar<MetadataEntity, int>(e => e.ObjectTypeCode, e => e.LogicalName == "inno_subject"), Is.EqualTo(1));
Assert.That(db.Scalar<MetadataEntity, int>(e => e.ObjectTypeCode, e => e.LogicalName.Equals("inno_subject")), Is.EqualTo(1));
}
}
}
}

0 comments on commit 7c7fbc8

Please sign in to comment.