为什么我从 .net 上的 Ormlite 得到“从范围引用但未定义的变量”错误,但它在 Mono 上运行良好?
Why do I get “variable referenced from scope but not defined” error from Ormlite on .net, but it works well on Mono?
我正在使用 ServiceStack Ormlite。我的代码是这样的:
var number = _conn.Count<Lot>(lot => lot.Labels.Contains("lookingString"));
我的问题是代码在 Mono 上运行良好,但在 .Net 框架中出现错误:
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。
不同平台的 Contains 方法是否不同?
这适用于 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
来尝试,例如:
我正在使用 ServiceStack Ormlite。我的代码是这样的:
var number = _conn.Count<Lot>(lot => lot.Labels.Contains("lookingString"));
我的问题是代码在 Mono 上运行良好,但在 .Net 框架中出现错误:
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。
不同平台的 Contains 方法是否不同?
这适用于 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
来尝试,例如: