Master Expression Trees in C# like a Senior

Поделиться
HTML-код
  • Опубликовано: 1 ноя 2024

Комментарии • 14

  • @alexanderbikk8055
    @alexanderbikk8055 Месяц назад +1

    Useful information, thanks for sharing!

  • @ismael3s
    @ismael3s Месяц назад

    This content is amazing, thanks for sharing

  • @YuvarajUV001
    @YuvarajUV001 Месяц назад

    Looks Complex but understandable. Thanks ❤

  • @omeruluocak368
    @omeruluocak368 Месяц назад

    Hi I've also used expression trees for dynamic filtering, searching etc. I've implemented a query builder class which can apply fitering, searching, sorting and returns a queryable to be used as EF core predicate.
    My question is, for example if we have many filter paramaters there will be lots of if conditions to check whether the value is null. How can we simplify this process using query builder class to rid of if checks. I wonder your comment.

    • @TuralSuleymaniTech
      @TuralSuleymaniTech  Месяц назад

      Hey, of course. We have a visitor pattern to get rid of 'ıf' checks everytime. Check of ExpressionVisitor class

  • @robertmrobo8954
    @robertmrobo8954 Месяц назад +1

    Why would one go this complex route instead of using IQueryable?
    var query = dbContext.Associations.AsQueryable();
    if (!string.IsNullOrEmpty(request.Name))
    {
    query = query.Where(a => a.Name.Contains(request.Name));
    }
    return await query.ToListAsync(cancellationToken: cancellationToken);

    • @MAUIMS-m4g
      @MAUIMS-m4g Месяц назад +1

      9:55

    • @robertmrobo8954
      @robertmrobo8954 Месяц назад +1

      @@MAUIMS-m4g The IFs in this case are readable and easy to maintain. There's no else.

    • @TuralSuleymaniTech
      @TuralSuleymaniTech  Месяц назад +3

      Hey Robert,
      Thanks for your comment! You’re absolutely right that using IQueryable with simple filtering like Contains works well in many cases. However, the power of expression trees comes into play when dealing with more complex scenarios.
      In your example, you're handling a specific condition (Contains) with a direct if..else approach, which is perfectly fine for simpler filters. But when you start dealing with a more extensive set of dynamic filters, such as combinations of comparison operators (>=,

  • @dr.angerous
    @dr.angerous Месяц назад

    Are you Indian or not. I can't stand them to even listen to.