Linq query RRS feed

  • Question

  • Hi, How can I make the following linq query?

    string[] x = {3,5,7}

    entidad.Areas.Where(d => d.Idarea "is inside x").ToList()

    .ForEach(d => d.SetRowState(EntityState.Deleted));

    I need the filter if Idarea is inside the string array x


    Monday, July 18, 2011 9:01 PM


  • string[] x = {3, 5, 7}
    var areas = from area entidad.Areas
             where x.Contains(d.Idarea)
             select area;
    foreach (Area area in areas)

    I would go with something like this. You could do the same thing using the syntax you have if you want, but I tend to prefer writing out the LINQ query instead of calling the methods directly. Also, you don't need to call ToList() - just use the foreach loop.

    You'll also need to replace Area in the foreach loop with the actual type of an item from the entidad.Areas collection.


    Check out My Blog for tech news, development tips, and other information for geeks like me.
    • Marked as answer by diegodamage82 Monday, July 18, 2011 10:17 PM
    Monday, July 18, 2011 9:59 PM