EntityFramework 6.0.2 でLinqKitを使い始めたばかりで、次の質問があります...
なぜこれを行うのですか:
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;
}
正常に動作します?