views:

30

answers:

1

Hi All,

I have an 3 tiered application where I need to get database results and populated the UI. I have a MessagesCollection class that deals with messages. I load my user from the database. On the instantiation of a user (ie. new User()), a MessageCollection Messages = new MessageCollection(this) is performed. Message collection accepts a user as a parameter.

 User user = user.LoadUser("bob");

I want to get the messages for Bob.

 user.Messages.GetUnreadMessages();

GetUnreadMessages calls my Business Data provider which in turn calls the data access layer. The Business data provider returns List.

My question is - I am not sure what the best practice is here - If I have a collection of messages in an array inside the MessagesCollection class, I could implement ICollection to provide GetEnumerator() and ability to traverse the messages. But what happens if the messages change and the the user has old messages loaded?

What about big message collections? What if my user had 10,000 unread messages? I don't think accessing the database and returning 10,000 Message objects would be efficient.

A: 

It appears that if you place a separate call to load the messages after the user then you are taking 2 round trips to the DB. If possible, I would consider making a single trip and loading the User with Messages in a single trip. In terms of large sets of data, you may want to consider some kind of paging mechanism. It would be impossible for the user to comprehend all the messages in a single view, therefore displaying them a page at a time would be preferable.

The collection will be able to track changes internally no problem(events or otherwise). You can expose the changes to your entity either using some custom event or something like the INotifyPropertyChanged interface.

Adam Fyles