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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:47:09+00:00 2026-06-14T20:47:09+00:00

I have an existing set of items in a database where a MultiSelectList of

  • 0

I have an existing set of items in a database where a MultiSelectList of Id’s allows Shifts to be added to an Operator.
Currently, an Operator has 3 Shifts assigned. This is now edited on the View to remove 1 Shift from the 3.

What is the best way to go through the existing set of items and determine which of the 3 to remove that isn’t found in the list of selected items.

I know the easiest method would be to remove all items in the database for the Operator and then insert the values from the MultiSelectList but thought there might be a way to use LINQ to select from existing where not in the list of Id’s

var existing = (from os in db.OperatorShifts
                where os.OperatorId == model.Id
                select os);

public List<Guid?> Shifts { get; set; }
public MultiSelectList AvailableShifts { get; set; }

model.Shifts
  • 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-14T20:47:11+00:00Added an answer on June 14, 2026 at 8:47 pm
    //asuming your db has these fields: db.Shifts, db.OperatorShifts
    //and model is the current Operator
    
    var existingShifts = (from os in db.OperatorShifts
                    where os.OperatorId == model.Id
                    select os).ToList();
    
    IEnumerable<Guid> newShiftIds = ?; //don't now how your selected shift ids got post back, figure it out yourself
    
    var shiftsToRemove = existingShifts.Where(e => newShiftIds.All(id => e.Id != id)).ToList();
    var shiftIdsToAppend = newShiftIds.Where(id => exising.All(e => e.Id != id)).ToList();
    
    foreach(var shift in shiftsToRemove)
    {
        db.OperatorShifts.Remove(shift);
    }
    
    foreach(var shiftId in shiftIdsToAppend)
    {
        db.OperatorShifts.Add(new OperatorShift{
            OperatorId = model.Id,
            ShiftId = shiftId
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an existing set of .net libraries that I wish to call from
I have an existing panel where I set the html manually with a variable
I have an existing program we've developed as a large set of Eclipse plugins.
I have a set of existing WCF services hosted in a .NET 3.0 app.
I have existing Linux shared object file (shared library) which has been stripped. I
We have an existing Firebird database which we wish to setup in an ASP.NET
I have set up a simple core data schema, where item objects are added
I'm using nHibernate on a webpage for viewing items from an already existing database.
I have an (existing) typed class of items: Items<T> T Value { get; }
I have existing code that uses CMNewProfileSearch to find then iterate over the color

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.