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 979505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:13:45+00:00 2026-05-16T04:13:45+00:00

i am using db4o in a asp.net web application, as you know when db4o

  • 0

i am using db4o in a asp.net web application, as you know when db4o returns a list of objects they are not ordered.

in my website, i run a query and get the last object in the results and work on it (some processing and then update one of its fields).

my question is, if when i am working on that object , if another user arrive and run that query again , the same object returns to him, and both of users get same object.

i don’t want to allow this to happen. how can i prevent it from happening ?

  • 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-16T04:13:45+00:00Added an answer on May 16, 2026 at 4:13 am

    Not sure if DB4O provides anything like this out of the box, but could implement some kind of pessimistic lock yourself, whereby the same object either won’t be returned or will be returned in a read-only mode. You’d need to maintain a list of objects being edited, and check this list each time you return your objects. But then there are problems such as users leaving and object getting stuck in ‘edit mode’ etc. You generally need some kind of service involving a timeout mechanism to deal with that. It can get complicated.

    Or do it optimistically, e.g. let both users edit it but only save changes from the first user, and give the second user a warning when they try to save it. Usually done with a timestamp.

    Edit

    To provide a concrete example, this C# code provides a basic way to ‘lock’ an object so it isn’t brought back every time. In real life it will be more complex though.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    
    namespace ListTest
    {
        class Program
        {
            static void Main(string[] args)
            {
                DataAccess dataAccess = new DataAccess();
    
                // get objects from database
                List<MyThing> things = dataAccess.GetThings();
                MyThing thingToWorkOn = things[things.Count-1];
                printThingList(things);
    
                // lock the object to work on
                dataAccess.LockThing(thingToWorkOn);
    
                // someone else gets the list - doesn't include thing being edited
                List<MyThing> moreThings = dataAccess.GetThings();
                printThingList(moreThings);
    
                // edit the object
                thingToWorkOn.Name = "Harrold";
                thingToWorkOn.Name = "Harry";
    
                // save the object and unlock it
                dataAccess.Save(thingToWorkOn);
                dataAccess.UnlockThing(thingToWorkOn);
    
                // now when someone else gets the list, includes all objects
                List<MyThing> evenMoreThings = dataAccess.GetThings();
                printThingList(evenMoreThings);
            }
    
            static void printThingList(List<MyThing> things)
            {
                Console.WriteLine("* Things *");
                things.ForEach(x => Console.WriteLine(x.Name));
                Console.WriteLine();
            }
        }
    
        // The objects you're working with.  Could just use 'object' or some interface.
        class MyThing : IEquatable<MyThing>
        {
            public string Name { get; set; }
    
            public bool Equals(MyThing other)
            {
                return other.Name == this.Name;
            }
        }
    
        // Class to get objects from database.
        class DataAccess
        {
            // simple list to store 'locked' objects
            private static List<MyThing> lockedThings = new List<MyThing>();
    
            // Get all objects except the locked ones
            public List<MyThing> GetThings()
            {
                List<MyThing> thingsFromDatabase = LoadThingsFromDatabase();
    
                var nonLockedThings = (from thing in thingsFromDatabase
                                       where !lockedThings.Contains(thing)
                                       select thing
                                        ).ToList<MyThing>();
    
                return nonLockedThings;
            }
    
            // lock an object so it can't be seen by anyone else
            public void LockThing(MyThing thingToLock)
            {
                lockedThings.Add(thingToLock);
            }
    
            // unlock an object
            public void UnlockThing(MyThing thingToLock)
            {
                lockedThings.Remove(thingToLock);
            }
    
            public void Save(MyThing thing)
            {
                // save to database
            }
    
            // dummy method to give us some objects
            private List<MyThing> LoadThingsFromDatabase()
            {
                return new List<MyThing>() {
                    new MyThing(){ Name="Tom" },
                    new MyThing(){ Name="Dick" },
                    new MyThing(){ Name="Harry" }
                };
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.