Working with Enumerators in Business Data Catalog (Moss 2007)

I was just working through some BDC examples and thought that the way DbEntityInstanceEnumerator is being used is a shame. So, instead of each time using the MoveNext method and a cast I wrote these little extension methods:

public static void Foreach(this DbEntityInstanceEnumerator instances, Action<DbEntityInstance> action)
{
    while (instances.MoveNext())
        action(instances.Current as DbEntityInstance);
}

public static void Foreach(this IEntityInstanceEnumerator instances, Action<IEntityInstance> action)
{
    while (instances.MoveNext())
        action(instances.Current);
}

Leave a Reply

Your email address will not be published. Required fields are marked *