Request advice with issue concerning BusinessListBase - need a fill method.

Request advice with issue concerning BusinessListBase - need a fill method.

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


Nicholas DL posted on Tuesday, July 03, 2007

Assume a business entity "Account":

public class Account : BusinessBase<Account> { ... }

Include an "Account" collection:

public class AccountList : BusinessListBase<AccountList, Account>
{
  ...
  protected override void DataPortal_Fetch(object criteria)
  {
    if(criteria is AccountList.FetchByAccountIDCriteria)
    {
      AccountList.FetchByAccountIDCriteria fetchcriteria = criteria as AccountList.FetchByAccountIDCriteria;

      //=== if 300 fetchcriteria.AccountIDs; 300 times Account.Fetch(accountid) ===
      foreach (string accountid in fetchcriteria.AccountIDs)
      {
        Account account = Account.Fetch(accountid);

        if(null != account) { this.Add(account); }
      }
    }
  }
}

The issue with BusinessListBase DataPortal_Fetch is that it has no access to the DataPortal; only a business entity may invoke the DataPortal.

In the "AccountList" snippet above, the collection creates a new "Account" entity for each provided account ID. Each newly created "Account" entity invokes its internal Fetch method.

This to me is a concern; were 300 account IDs supplied, 300 separate database invocations would occur.

I am familiar with almost every line of CSLA yet I cannot find a batch "Fill" method for a collection in which the DB may return 300 rows and all the "Account" entities created with one DB call.

Has anyone a work around?

Thanks all!

Nick

ajj3085 replied on Thursday, July 05, 2007

BLB can use the dataportal.  Are you sure you had "using Csla;" in your code?

Typically I have the collection fetch all the data, and the BO implements an internal factory method that takes the data object from which to load, instead of hitting the db itself.

Nicholas DL replied on Thursday, July 05, 2007

My mistake; after I read your message, I inspected some of the mods I had created within CSLA and realized that the Command Pattern I implemented in the business entity base was not implemented in the list base as well.

I preferred not to permit the entity access to the DAL and created a command pattern in which Fetch simply called Execute() for each command object provided.

I have extended his FW quite significantly; adding methods such as these to the list base:

  • TrueForAll(Predicate<C> predicate);
  • ISet<U> ConvertAll<U>(Converter<C, U> converter);
  • ISet<C> FindAll(Predicate<C> predicate);
  • ForEach(Action<C> action);
  • ValidateAll(Predicate<C> predicate);
  • C [] ToArray();
  • List<C> Where(string property, WhereParameters parameter, string value);
Thanks for the help!

Copyright (c) Marimer LLC