Database access through collections
- by Mike
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.