Collection options using Entity Framework?

In my last project, I decided to use the Entity Framework, and everything went well, until I tried to get the data from "where to", I got an error.

After a tiny search, I came up with this post and which I posted .

This is what I'm trying to do.

var all = fooelements
              .Where(l=>controlsToGet
                            .Contains(l.Control.Name));

Is it possible to handle it with lambda expressions or linq with Entity Framework?

thanks

+3
source share
2 answers

Based on the previous answer, I have a hint that allows you to do this here:

Tip 8 - How to write WHERE IN style queries using LINQ to Entities

,

- Entity Framework

Entity Framework

+3

WHERE IN EF, WHERE, :

    Expression<Func<FooEntity, bool>> seed = l => false;
    var predicate = controlsToGet.Aggregate(seed,
        (e, c) => Expression.Lambda<Func<DataEventAttribute, bool>>(
            Expression.OrElse(
                Expression.Equal(
                    Expression.Property(
                        Expression.Property(
                            e.Parameters[0],
                            "Control"),
                        "Name"),
                    Expression.Constant(c)),
                e.Body),
            e.Parameters));

    var all = fooelements.Where(predicate);

predicate, , :

l => ((l.Control.Name = ctrl5) || l.Control.Name = ctrl4 || ... || False )
+1

Source: https://habr.com/ru/post/1716127/


All Articles