BusinessListBase Batch Insert or AddRange solution

BusinessListBase Batch Insert or AddRange solution

Old forum URL: forums.lhotka.net/forums/t/11433.aspx


j0552 posted on Tuesday, June 26, 2012

 

Hi

 

I have a BLB with  AddRange and RemoveRange methods, e.g.

 

        public void AddRange(IEnumerable<int> range)

        {

            var rlce = RaiseListChangedEvents;

            RaiseListChangedEvents = false;

 

            if (range != null)

            {

                foreach (var id in range)

                {

                    Add(id);

                }

            }

 

            RaiseListChangedEvents = rlce;

        }

 

        public void Add(int id)

        {

            if (!Contains(id))

            {

                var account = AccountCreator.GetCreator(id).Result;

                Add(account);

            }

        }

 

The method is called from an MVC controller action. The problem is the range parameter could contain a few thousand ids which makes it very slow with the current implementation. Is there a way to suppress all events, rules during the inserts. I'd want to raise a single list change event at the end of the batch.

 

Setting RaiseListChangedEvents to false in the AddRange method doesn’t seem to have any effect.

 

What are my options to improve performance?

 

Thank you

Andrew

 

Copyright (c) Marimer LLC