Database access through collections

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2010-03-30T23:16:30Z Indexed on 2010/03/30 23:23 UTC
Read the original article Hit count: 345

Filed under:
|
|
|
|

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.

© Stack Overflow or respective owner

Related posts about data

Related posts about access