locked
Deleting entity records from a query RRS feed

  • Question

  • I need to delete existing records from an entity in a query because I plan to insert new records into the entity. I get stack overflow if I do the following in foreach statement.

    Any Ideas?

    partial void Query_Executing(QueryExecutingDescriptor queryDescriptor){ 
                foreach (AdvisorInterest rec in AdvisorInterests)                  
                    rec.Delete();
     
              AdvisorInterest newAdvisorInterest = AdvisorInterests.AddNew();
            newAdvisorInterest.Name = "dsmith";
             newAdvisorInterest.Interest = 5000;
             SaveChanges();

    Tuesday, May 21, 2013 1:57 AM

All replies

  • I think I see what you want to do.  You may need to create a variable to hold the AdvisorInterests and then foreach over that.  Something like:

    var advisorInterests = AdvisorInterests.ToList();
    
    foreach (AdvisorInterest rec in advisorInterests)
    {
    rec.Delete();
    }

    I typically wouldn't do this type of thing where you are doing it so my suggestion may not work.


    Brian

    Tuesday, May 21, 2013 2:07 PM