views:

99

answers:

2

I have a statment like this:

foreach (var container in modelEntities.
   Where(me => me.Value.ModelEntityType == (int)EntityType.Container))

Now I want to add an or clause to this where statement, however I can't seem to be able to do it.

Is there a way? or do I have to do the

var containers = (from me in modelEntities
   where me.Value.ModelEntityType == (int)EntityType.Container ||
   me.Value.ModelEntityType == (int)EntityType.SubForm
   select me);

foreach (var container in containers)
+3  A: 

You can just add the or to the first form:

foreach (var container in modelEntities.
    Where(me => me.Value.ModelEntityType == (int)EntityType.Container ||
      me.Value.ModelEntityType == (int)EntityType.SubForm))
Henk Holterman
doh! User error... I had tried that, but must got a bracket wrong or something (I blame my slow VM)
Grayson Mitchell
A: 

add all options to a list and query that list instead.

var options = new [] {(int)EntityType.Container, (int)EntityType.SubForm};

var containers = modelEntities.Where(m => options.Contains(m.Value.ModelEntityType));
Carl Hörberg