Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 689117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:17:58+00:00 2026-05-14T02:17:58+00:00

I have a database with Users. Users have Items. These Items can change actively.

  • 0

I have a database with Users.
Users have Items.

These Items can change actively.
How do you access the items in a collection type format?
For the user, I fill all the user properties at the time of instantiation.
If I load the user’s items at the time of the instantiation, and the items change,
they will have old data.

I was thinking, maybe I need an ItemCollection class and have that a field/property apart of the user class, that way to traverse all the user’s items I could use a foreach loop.

So, my question is, what is the best practice/best way of accessing the items from a database using some sort of collection? On accessing the particular Item, it needs to get the latest database information, and when the user does do a foreach loop, the latest item information must be available.

I.e. What I’m trying to do

Console.WriteLine(User.Items[3].ID); returns 5.
//this updates the item information and saves it to the database.
User.Items[3].ID = 13; 

//Add a new item to the database.
User.Items.Add(new Item { id = 17});

foreach (Item item in User.Items) {
    //this would traverse all items in the database.
    //not some cached copy at the time of instantiation of the user.
}

Edit: Sorry, I’ve written this question a little wrong.
I’m using Linq currently, but I have Classes mapping to business objects.
When I do a traverse on a business object, I would like it to go to the Linq datacontext and get the information.

When I implement a new class “ItemCollection” which implements interface IList,
what do I need to do to get it returning Items?

With the User.Items[3], is implemented in the public Item this[int index] method.
Should the index method use the linq.Skip operator to get the index of the item in the database?

I’m just a little confused about mapping business object collections to database.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:17:58+00:00Added an answer on May 14, 2026 at 2:17 am

    While this is possible to do, it would require some unusual requirements to be necessary.

    First of all, this would produce an excessive amount of traffic between your database and your application. Second, in a concurrent environment, this will introduce a large amount of race conditions.

    Just for a quick example, the code segment:

    User.Items[3].ID = 13; 
    User.Items[3].Color = Color.Blue; 
    

    Could produce states which are not allowed, however it exists in the database for at least a moment because of the eagerness to persist state. Also the above code segment would access the database twice in order to make a simple update. And there it is much more difficult to guarantee that this change will be atomic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple database with two tables. Users and Configurations. A user has
We have a SQL Server 2005 database, and currently all our users are connecting
I have a large database of users (~200,000) that I'm transferring from a ASP.NET
So I have a database schema like this: Users UserId RoleUserXRef RoleUserId RoleId UserId
I have a database that I used specifically for logging actions of users. The
I have a table, users, in an Oracle 9.2.0.6 database. Two of the fields
I have a database with user 'dbo' that has a login name domain\xzy. How
I have a database in single user mode and I am trying to drop
I have a postgres database with a user table (userid, firstname, lastname) and a
I know that Open Office Database uses a java database backend. Does anyone have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.