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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:45:55+00:00 2026-05-28T15:45:55+00:00

I need a way to determine which rows were deleted from the DB, given

  • 0

I need a way to determine which rows were deleted from the DB, given a list of IDs of interest.
Something like:

var idsOfInterest = new int[] {1,2,3,4};
idsOfInterest.Except(Datacontext.Table.Select(tbl=>tbl.ID)).Dump();

How can I do that? What’s an optimal LINQ query for it?

EDIT: Is it possible to do it in one step(a single DB query), without querying the existing IDs and then applying Except?

  • 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-28T15:45:56+00:00Added an answer on May 28, 2026 at 3:45 pm

    Your own code will do fine. However, there might be a performance problem since you are pulling all IDs from the database, so the following is more efficient.

    var idsInDatabase =
        from t in DataContext.Table
        where idsOfInterest.Contains(t.ID)
        select t.ID;
    
    var idsDeletes = idsOfInterest.Except(idsInDatabase);
    

    UPDATE:

    From your update I understand, you would like to retrieve all missing IDs from the database, which is quite hard to do, since you want the IDs that don’t exist anymore from the database.

    If you would try to do this with plain old SQL, you would need either a table that contains a big list of numbers { 0, 1, 2, 3, … } to join against (since your Table does not contain all IDs anymore) or you would create an inner query or table valued function). That might look like this:

    SELECT  x.id
    FROM    (
                SELECT    1 as id
                UNION ALL
                SELECT    2
                UNION ALL
                SELECT    3
                UNION ALL
                SELECT    3) x
            LEFT OUTER JOIN Table t ON x.id = t.ID
    WHERE   t.ID IS NULL
    

    As far as I know, there is no way to translate such construct to LINQ to SQL. The same holds for table valued functions.

    So what you can do is join your Table with some sort of Numbers table, but I personally wouldn’t do that, since you’re just over complicating things.

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

Sidebar

Related Questions

I would like to know if there is a way to determine which sub-folders
I need to be able to determine which page the user just came from
I need a way to determine the type of an HTML element in JavaScript.
I need a way to determine whether the computer running my program is joined
Executive summary: I need a way to determine whether a Windows process I've spawned
We need to determine a quick way for our web application deployed in a
Need a way to allow sorting except for last item with in a list.
I need a way to build C++ code from UML diagrams and vice versa.
I'm wondering if there's a simple way for a Word macro to determine which
I need to programmatically add and remove rows from a Word 2010 table. Unfortunately

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.