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

  • SEARCH
  • Home
  • 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 9062051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:38:18+00:00 2026-06-16T15:38:18+00:00

Perhaps I’m not going about this the right way, so if anyone can steer

  • 0

Perhaps I’m not going about this the right way, so if anyone can steer me in the right direction, I would greatly appreciate it.

I have a lot of methods in my code that do something like

void UpdateWidget(Widget updatedWidget)
{
    IDocumentSession session = documentStore.OpenSession();
    oldWidget = session.Load<Widget>("widgets" + widget.Id);

    oldWidget.Name = updatedWidget.Name;
    oldWidget.Color = updatedWidget.Color;
    oldWidget.CreatedDateTime = updatedWidget.CreatedDateTime;
    session.SaveChanges();
}

What I’d LIKE to do is something like the following (assuming the IDs are the same of course)

void UpdateWidget(Widget updatedWidget)
{
    IDocumentSession session = documentStore.OpenSession();
    oldWidget = session.Load<Widget>("widgets" + widget.Id);
    oldWidget = updatedWidget
    session.SaveChanges();
}

Can someone help me with some syntax or pattern that can get me close to this? Is there a way to use object tracking in Raven to accomplish this? Or do I need some sort of mapping tool like automapper (which I don’t understand very well)

thanks in advance!

  • 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-06-16T15:38:19+00:00Added an answer on June 16, 2026 at 3:38 pm

    You can just store the updated object and it will replace the old one if it exists already.

    void UpdateWidget(Widget updatedWidget)
    {
        using (var session = documentStore.OpenSession())
        {
            session.Store(updatedWidget);
            session.SaveChanges();
        }
    }
    

    However, you have to consider the concurrency effects.

    If you have optimistic concurrency disabled, it should just accept the new document, but you risk stepping on others changes. If you have it enabled, you need to either do the Load and update in the same session, or you need to track the etag of the document yourself.

    Review the following RavenDB knowledge base article for details: http://ravendb.net/kb/16/using-optimistic-concurrency-in-real-world-scenarios

    ALSO – not related to your question, but it’s very important that your session is being disposed properly. Wrap it in a using statement. (Or if it’s being injected, then make sure your IoC has the appropriate lifetime scope and is disposing it when appropriate.)

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

Sidebar

Related Questions

Perhaps I am going about this the wrong way. Let me know Using Swing
Perhaps I'm going about this the wrong way, but I'm using HXT to read
Perhaps I'm going about this all wrong (and please tell me if I am),
Perhaps you can help me find this in the docs. I'm using pound-quote to
Perhaps any of you can help me with this anoying problem. I have long
Perhaps I'm not using the right terminology, but I'm struggling to try to find
Perhaps I'm just not fully understanding the documentation right now but is there a
Perhaps my understanding of the Ajax Modal popup is not correct. What I would
Perhaps this isn't the best forum for this question. If so, would one of
Perhaps this is mere wishful thinking, but is there a simple way (in ASP.NET)

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.