gpt4 book ai didi

c# - 如何将 BinaryExpression 转换为 Expression>?

转载 作者:太空宇宙 更新时间:2023-11-03 19:47:48 24 4
gpt4 key购买 nike

<分区>

我有以下简单的扩展类

public static class ExpressionOrExtension
{
public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> source, Expression<Func<T, bool>> expression)
{
if (source == null)
return expression;
return Expression.Or(source, expression);
}
}

但是 Expression.Or 返回一个 BinaryExpression - 我怎样才能让它返回 Expression<Func<T, bool>>相反?

这就是我尝试使用 Entity Framework 来使用该方法的方式

    public IQueryable<BookVerse> FindByVerseReferences(string bookCode, params VerseReference[] verseReferences)
{
Expression<Func<BookVerse, bool>> conditions = null;
foreach(VerseReference verseReference in verseReferences ?? new VerseReference[0])
{
conditions = conditions.Or<BookVerse>(x =>
x.BookCode == bookCode
&& x.Chapter == verseReference.Chapter
&& x.FirstVerse <= verseReference.LastVerse
&& x.LastVerse >= verseReference.FirstVerse);
}
return MyDbContext.BookVerses.Where(conditions);
}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com