fixes SQL IN expression
This commit is contained in:
@@ -540,8 +540,9 @@ namespace Umbraco.Core.Persistence.Querying
|
||||
|
||||
//special case, if it is 'Contains' and the argumet that Contains is being called on is
|
||||
//Enumerable and the methodArgs is the actual member access, then it's an SQL IN claus
|
||||
if (m.Arguments.Count == 2
|
||||
&& m.Object == null
|
||||
if (m.Object == null
|
||||
&& m.Arguments[0].Type != typeof(string)
|
||||
&& m.Arguments.Count == 2
|
||||
&& methodArgs.Length == 1
|
||||
&& methodArgs[0].NodeType == ExpressionType.MemberAccess
|
||||
&& TypeHelper.IsTypeAssignableFrom<IEnumerable>(m.Arguments[0].Type))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
@@ -156,5 +157,21 @@ namespace Umbraco.Tests.Persistence.Querying
|
||||
Assert.AreEqual("@test", modelToSqlExpressionHelper.GetSqlParameters()[2]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Sql_In()
|
||||
{
|
||||
var userNames = new[] {"hello@world.com", "blah@blah.com"};
|
||||
|
||||
Expression<Func<IUser, bool>> predicate = user => userNames.Contains(user.Username);
|
||||
var modelToSqlExpressionHelper = new ModelToSqlExpressionVisitor<IUser>();
|
||||
var result = modelToSqlExpressionHelper.Visit(predicate);
|
||||
|
||||
Debug.Print("Model to Sql ExpressionHelper: \n" + result);
|
||||
|
||||
Assert.AreEqual("[umbracoUser].[userLogin] IN (@1,@2)", result);
|
||||
Assert.AreEqual("hello@world.com", modelToSqlExpressionHelper.GetSqlParameters()[1]);
|
||||
Assert.AreEqual("blah@blah.com", modelToSqlExpressionHelper.GetSqlParameters()[2]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user