【发布时间】:2015-10-24 07:16:33
【问题描述】:
我正在尝试在 linq 表达式中使用以下代码,我在 this question 但是,如果数据库字段为空,则会失败。
public static IQueryable<T> FieldsAreEqualOrBothNullOrEmpty<T>(
this IQueryable<T> source,
Expression<Func<T, string>> member,
string value)
{
Expression body;
if (string.IsNullOrEmpty(value))
{
body = Expression.Call(typeof(string), "IsNullOrEmpty", null, member.Body);
}
else
{
body = Expression.Equal(
Expression.Call(member.Body, "ToLower", null),
Expression.Constant(value.ToLower(), typeof(string)));
}
return source.Where(Expression.Lambda<Func<T, bool>>(body, member.Parameters));
}
在我看来就像是代码
Expression.Call(member.Body, "ToLower", null)
是问题所在,但我不知道该用什么来代替它。
【问题讨论】:
标签: c# linq entity-framework-6