Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit b50df53

Browse files
author
Thomas Grassauer
committed
fixed Sql.In array issue
1 parent bb0bf4b commit b50df53

File tree

3 files changed

+39
-18
lines changed

3 files changed

+39
-18
lines changed

src/ServiceStack.OrmLite.SqlServerTests/ForeignKeyAttributeTests.cs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ public void Setup()
1111
{
1212
using (var dbConn = ConnectionString.OpenDbConnection())
1313
{
14+
dbConn.DropTable<TypeWithOnDeleteAndUpdateCascade>();
15+
dbConn.DropTable<TypeWithOnDeleteSetNull>();
16+
dbConn.DropTable<TypeWithOnDeleteSetDefault>();
17+
dbConn.DropTable<TypeWithOnDeleteRestrict>();
18+
dbConn.DropTable<TypeWithOnDeleteNoAction>();
19+
dbConn.DropTable<TypeWithOnDeleteCascade>();
20+
dbConn.DropTable<TypeWithSimpleForeignKey>();
21+
dbConn.DropTable<ReferencedType>();
22+
1423
dbConn.CreateTable<ReferencedType>(true);
1524
}
1625
}
@@ -98,22 +107,6 @@ public void CanCreateForeignWithOnDeleteSetNull()
98107
dbConn.CreateTable<TypeWithOnDeleteSetNull>(true);
99108
}
100109
}
101-
102-
[TestFixtureTearDown]
103-
public void TearDwon()
104-
{
105-
using (var dbConn = ConnectionString.OpenDbConnection())
106-
{
107-
dbConn.DropTable<TypeWithOnDeleteAndUpdateCascade>();
108-
dbConn.DropTable<TypeWithOnDeleteSetNull>();
109-
dbConn.DropTable<TypeWithOnDeleteSetDefault>();
110-
dbConn.DropTable<TypeWithOnDeleteRestrict>();
111-
dbConn.DropTable<TypeWithOnDeleteNoAction>();
112-
dbConn.DropTable<TypeWithOnDeleteCascade>();
113-
dbConn.DropTable<TypeWithSimpleForeignKey>();
114-
dbConn.DropTable<ReferencedType>();
115-
}
116-
}
117110
}
118111

119112
public class ReferencedType

src/ServiceStack.OrmLite/Expressions/SqlExpressionVisitor.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Reflection;
@@ -1114,15 +1115,15 @@ protected virtual object VisitSqlMethodCall(MethodCallExpression m)
11141115
StringBuilder sIn = new StringBuilder();
11151116
foreach (Object e in inArgs)
11161117
{
1117-
if (e.GetType().ToString() != "System.Collections.Generic.List`1[System.Object]")
1118+
if (!typeof(ICollection).IsAssignableFrom(e.GetType()))
11181119
{
11191120
sIn.AppendFormat("{0}{1}",
11201121
sIn.Length > 0 ? "," : "",
11211122
OrmLiteConfig.DialectProvider.GetQuotedValue(e, e.GetType()));
11221123
}
11231124
else
11241125
{
1125-
var listArgs = e as IList<Object>;
1126+
var listArgs = e as ICollection;
11261127
foreach (Object el in listArgs)
11271128
{
11281129
sIn.AppendFormat("{0}{1}",

tests/ServiceStack.OrmLite.Tests/ExpressionVisitorTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,33 @@ public void Can_Select_using_IN()
100100
Assert.AreEqual(2, target.Count);
101101
}
102102

103+
[Test]
104+
public void Can_Select_using_IN_using_params()
105+
{
106+
var visitor = OrmLiteConfig.DialectProvider.ExpressionVisitor<TestType>();
107+
visitor.Where(q => Sql.In(q.Id, 1, 2, 3));
108+
var target = ConnectionString.OpenDbConnection().Select(visitor);
109+
Assert.AreEqual(3, target.Count);
110+
}
111+
112+
[Test]
113+
public void Can_Select_using_IN_using_int_array()
114+
{
115+
var visitor = OrmLiteConfig.DialectProvider.ExpressionVisitor<TestType>();
116+
visitor.Where(q => Sql.In(q.Id, new[] {1, 2, 3}));
117+
var target = ConnectionString.OpenDbConnection().Select(visitor);
118+
Assert.AreEqual(3, target.Count);
119+
}
120+
121+
[Test]
122+
public void Can_Select_using_IN_using_object_array()
123+
{
124+
var visitor = OrmLiteConfig.DialectProvider.ExpressionVisitor<TestType>();
125+
visitor.Where(q => Sql.In(q.Id, new object[] { 1, 2, 3 }));
126+
var target = ConnectionString.OpenDbConnection().Select(visitor);
127+
Assert.AreEqual(3, target.Count);
128+
}
129+
103130
[Test]
104131
public void Can_Select_using_Startswith()
105132
{

0 commit comments

Comments
 (0)