为什么我从.net上的Ormlite获得“范围但未定义的变量引用”错误,但它在Mono上运行良好?

时间:2016-08-17 07:44:59

标签: servicestack ormlite-servicestack

我正在使用ServiceStack Ormlite。我的代码喜欢这个:

var number = _conn.Count<Lot>(lot => lot.Labels.Contains("lookingString"));

我的问题是代码在Mono上运行良好,但从.Net framework获得错误:

Message: [InvalidOperationException: variable 'lot' of type 'pM.Models.Entity.Lot' referenced from scope '', but it is not defined]

 System.Linq.Expressions.Compiler.VariableBinder.Reference(ParameterExpression node, VariableStorageKind storage):142
 System.Linq.Expressions.Compiler.VariableBinder.VisitParameter(ParameterExpression node):10
 System.Linq.Expressions.Compiler.VariableBinder.VisitUnary(UnaryExpression node):59
 System.Linq.Expressions.ExpressionVisitor.VisitMember(MemberExpression node):13
 System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node):12
 System.Linq.Expressions.ExpressionVisitor.Visit(ReadOnlyCollection`1 nodes):26
 System.Linq.Expressions.Compiler.VariableBinder.VisitLambda[T](Expression`1 node):88
 System.Linq.Expressions.Compiler.LambdaCompiler.Compile(LambdaExpression lambda, DebugInfoGenerator debugInfoGenerator):0
 ServiceStack.OrmLite.SqlExpression`1.VisitMethodCall(MethodCallExpression m):87
 ServiceStack.OrmLite.SqlExpression`1.VisitBinary(BinaryExpression b):135
 ServiceStack.OrmLite.SqlExpression`1.Where(Expression`1 predicate):12
 ServiceStack.OrmLite.ReadExpressionCommandExtensions.Scalar[T,TKey](IDbCommand dbCmd, Expression`1 field, Expression`1 predicate):26
 ServiceStack.OrmLite.OrmLiteExecFilter.Exec[T](IDbConnection dbConn, Func`2 filter):16
 pM.Api.LabelReadHelper.GetUsage[T](String labelName) in c:\TeamCity\buildAgent\work\b85b83a981467d5b\pM.Api\Common\Labels\Template\LabelReadHelper.cs:23

在Mono上,LastSql是这样的:

SELECT COUNT(*) FROM `Lot` WHERE (upper(`Labels`) like '%lookingString%' AND (`CustomerId` = 'a54f02ee-cc74-4b4d-845d-6db2efb1f5dc'));

我的ServiceStack.Ormlite版本是4.0.50。

包含方法在平台之间是否有效?

1 个答案:

答案 0 :(得分:2)

这适用于OrmLite的最新 v4.0.62 ,您可try out Live in Gistlyn

public class Lot
{
    [AutoIncrement]
    public long Id { get; set; }
    public string Labels { get; set; }
}

db.CreateTable<Lot>();

db.Insert(new Lot { Labels = "foo" });
db.Insert(new Lot { Labels = "bar" });
db.Insert(new Lot { Labels = "qux" });
db.Insert(new Lot { Labels = "foo,bar,qux" });

var count = db.Count<Lot>(x => x.Labels.Contains("bar"));

"Labels with 'bar': {0}".Print(count); //= 2

它在Mono / Linux中具有相同的行为,您可以尝试使用mono.gistlyn.com,例如: