我刚开始将LinqKit与 EntityFramework 6.0.2 一起使用,我有以下问题......
为什么会这样:
public static readonly Expression<Func<MyEnum, string>> ConvertToString = e =>
e == MyEnum.One
? "one"
: e == MyEnum.Two
? "two"
: "zero";
private static string GetSomethingElse(IQueryable<EnumTest> things)
{
var ret = things
.AsExpandable()
.Select(c => Program.ConvertToString.Invoke(c.SomeEnum))
.First();
return ret;
}
扔:
An unhandled exception of type 'System.InvalidCastException'
occurred in LinqKit.dll
Additional information: Unable to cast object of type
'System.Linq.Expressions.FieldExpression' to type
'System.Linq.Expressions.LambdaExpression'.
但是这个:
private static string GetSomething(IQueryable<EnumTest> things)
{
Expression<Func<MyEnum, string>> ConvertToString = e => e == MyEnum.One
? "one"
: e == MyEnum.Two
? "two"
: "zero";
var ret = things
.AsExpandable()
.Select(c => ConvertToString.Invoke(c.SomeEnum))
.First();
return ret;
}
工作正常?