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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:21:05+00:00 2026-06-18T08:21:05+00:00

I have a simple IBackgroundTask implementation that performs a query and then either performs

  • 0

I have a simple IBackgroundTask implementation that performs a query and then either performs an insert or one or more updates depending on whether a specific item exists or not. However, the updates are not persisted, and I don’t understand why. New items are created just as expected.

The content item I’m updating has a CommonPart and I’ve tried authenticating as a valid user. I’ve also tried flushing the content manager at the end of the Sweep method. What am I missing?

This is my Sweep, slightly edited for brevity:

public void Sweep()
{
    // Authenticate as the site's super user
    var superUser = _membershipService.GetUser(_orchardServices.WorkContext.CurrentSite.SuperUser);
    _authenticationService.SetAuthenticatedUserForRequest(superUser);

    // Create a dummy "Person" content item
    var item = _contentManager.New("Person");
    var person = item.As<PersonPart>();
    if (person == null)
    {
        return;
    }
    person.ExternalId = Random.Next(1, 10).ToString();
    person.FirstName = GenerateFirstName();
    person.LastName = GenerateLastName();

    // Check if the person already exists
    var matchingPersons = _contentManager
        .Query<PersonPart, PersonRecord>(VersionOptions.AllVersions)
        .Where(record => record.ExternalId == person.ExternalId)
        .List().ToArray();
    if (!matchingPersons.Any())
    {
        // Insert new person and quit
        _contentManager.Create(item, VersionOptions.Draft);
        return;
    }

    // There are at least one matching person, update it
    foreach (var updatedPerson in matchingPersons)
    {
        updatedPerson.FirstName = person.FirstName;
        updatedPerson.LastName = person.LastName;
    }

    _contentManager.Flush();
}
  • 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-18T08:21:06+00:00Added an answer on June 18, 2026 at 8:21 am

    Try to add _contentManager.Publish(updatedPerson). If you do not want to publish, but just to save, you don’t need to do anything more, as changes in Orchard as saved automatically unless the ambient transaction is aborted. The call to Flush is not necessary at all. This is the case both during a regular request and on a background task.

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

Sidebar

Related Questions

I have simple php validation form that is halfway working. If you leave the
I have simple database - one table with 6 collumns. 3 of them i
I have simple win service, that executes few tasks periodically. How should I pass
I have simple query which is taking around 7-8 seconds for to retreive the
I have simple chat program using WCF service. One service use for server and
I have simple AJAX function that uses jQuery to return an array of 300
I have simple test project which creates a frame and adds one JTextPane to
I have simple login form in my website. In given requirements stands, that password
i have simple singleton that sets pdo object from factory class , in the
I have simple html code that plays YouTube video after click on the image:

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.