locked
issue with collection RRS feed

  • Question

  • cannot use foreach loop after this chunk of code:  

     

                           BusinessEntityCollection collection = new BusinessEntityCollection();
                            DynamicEntity seatRecord = null;
                            collection = retrieved.BusinessEntityCollection;
                            if (collection != null)
                            {
                                seatRecord = (DynamicEntity)collection.BusinessEntities[0];
                            }

     

     

    foreach (BusinessEntityCollection r in seatRecord)

      {

      }

    how are we meant to use foreach for a collection?

     


    • Edited by CRM2011 Tuesday, November 29, 2011 4:12 PM
    Tuesday, November 29, 2011 4:11 PM

Answers

  • You are not iterating correctly.    I also have a question about your enitty types.  You have a dynamicentity listed above but your name is CRM 2011. This would be a conflict as dynamicentity was only for 4.0 and not for 2011 which uses a different class that is just called entity.

    Your syntax should be like this.

    foreach (Entity ent in collection.Entities)

    {

    }


    Jamie Miley
    Check out my about.me profile!
    http://mileyja.blogspot.com
    Linked-In Profile
    Follow Me on Twitter!
    Tuesday, November 29, 2011 4:17 PM
    Moderator
  • try with this

    foreach (BusinessEntity r in seatRecord.BusinessEntities)

      {

      }


    Thanks Anil Chelasani
    • Proposed as answer by Anil_Ch Wednesday, November 30, 2011 5:03 AM
    • Marked as answer by Jamie MileyModerator Sunday, April 1, 2012 7:58 PM
    Wednesday, November 30, 2011 5:03 AM

All replies

  • You are not iterating correctly.    I also have a question about your enitty types.  You have a dynamicentity listed above but your name is CRM 2011. This would be a conflict as dynamicentity was only for 4.0 and not for 2011 which uses a different class that is just called entity.

    Your syntax should be like this.

    foreach (Entity ent in collection.Entities)

    {

    }


    Jamie Miley
    Check out my about.me profile!
    http://mileyja.blogspot.com
    Linked-In Profile
    Follow Me on Twitter!
    Tuesday, November 29, 2011 4:17 PM
    Moderator
  • try with this

    foreach (BusinessEntity r in seatRecord.BusinessEntities)

      {

      }


    Thanks Anil Chelasani
    • Proposed as answer by Anil_Ch Wednesday, November 30, 2011 5:03 AM
    • Marked as answer by Jamie MileyModerator Sunday, April 1, 2012 7:58 PM
    Wednesday, November 30, 2011 5:03 AM