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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:39:25+00:00 2026-06-16T18:39:25+00:00

I running the Windows server version of Redis and then have a little client

  • 0

I running the Windows server version of Redis and then have a little client application, and I cant find out how I update a value in a datatype I already have in the database

I have this Leader class I would like to update if it exists for a given District, else create an new entry

public class Leader
{
    public Employee Employee { get; set; }
    public District District { get; set; }
}

    public void SetLeader(District district, Employee employee)
    {
        using (var leaderSession = _redisClient.GetTypedClient<Leader>())
        {
            var leader = leaderSession.GetAll().SingleOrDefault(x => x.District.Id == district.Id);
            if (leader != null)
            {
                leader.Employee = employee;
            }
            else
            {
                leader = new Leader{District = district, Employee = employee};
            }
            leaderSession.Store(leader);
        }
    }

But when I do this I just get an extra entry in the database, so Store is not the right command to use, but which should I use?

The only solution I can come up with is delete the old one and store a new one, but thats seems a bit ineffective? (Not that it matters in my example, but still)

Edit: doing delete dont work either, it still creates a new one and keeps the old one.

    public void SetLeader(District district, Employee employee)
    {
        using (var leaderSession = _redisClient.GetTypedClient<Leader>())
        {
            var leader = leaderSession.GetAll().SingleOrDefault(x => x.District.Id == district.Id);
            if (leader != null)
            {
                leaderSession.Delete(leader);
            }

            leader = new Leader { District = district, Employee = employee };
            leaderSession.Store(leader);
        }
    }

Edit 2 Adding a Id field to Leader was apparently necessary for it to distinguish the different rows

So changing it to this works

public class Leader
{
    public long Id { get; set; }
    public Employee Employee { get; set; }
    public District District { get; set; }
}
  • 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-16T18:39:27+00:00Added an answer on June 16, 2026 at 6:39 pm

    Adding a Id field to Leader was apparently necessary for it to distinguish the different rows

    So changing it to this works

    public class Leader
    {
        public long Id { get; set; }
        public Employee Employee { get; set; }
        public District District { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .net 2.0 web application that is running on Windows server 2003
I have a process running under Windows Server 2003 SP2. When I want to
I have a virtual machine running windows 2003 server. It is on a separate
I have a asp.net webservice running in windows server 2003, i want it read/write
I have followed this guide to install Solr in TomCat running on Windows Server
I have a ASP.NET 3.5 website running on Windows Server 2003 and I'm using
I have installed TFS 2010 on a new server (vmware running windows server 2008
I am running Windows Server 2003 and need to install a version of GD.
Running on Windows Server 2008 R2 with Windows 7 client. I downloaded and installed
I have several web applications running on an Windows Server 2003 with IIS 6.0.

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.