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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:36:19+00:00 2026-05-18T20:36:19+00:00

I have a process that extracts customer info from multiple databases (MySql) based on

  • 0

I have a process that extracts customer info from multiple databases (MySql) based on a timestamp. I store this data into a DataTable. The data table represents updates to existing customer info as well as new customer info.

I want to delete any dupes in the destination database (SqlServer) based on one constant value, CompanyID, and the CustomerID. So, I thought a join would give me the RecordIDs of the dupes in the destination DB, pass the List<int> (or some collection mechanism) to the DELETE method.

What I have:

using (var context = new DataContext(SqlConnection))
{
    var tblSource = context.GetTable<tblCustomerInfo>();
    var dupeIDs = from currCust in tblSource
                  join newCust in myTable.AsEnumerable() on currCust.CompanyID equals newCust.Field<string>("CompanyID")
                  where currCust.CustomerID.Equals(newCust.Field<int>("CustomerID")
                  select currCust.RecordID;
}

This obviously does not work. I will update with the exact error messages in a bit, but this doesn’t compile.

First, is my join syntax even correct for what I am wanting to achieve?

Second, how can I write this Linq to join between a DataTable and the destination SqlServer database?

Afterthought – is it possible to, once I have a collection of dupe RecordIDs, use Linq to DELETE records from the destination database?

Edit
To clarify the process, I have incoming data tables like so and contained in a DataSet:

Table1
CompanyID    CustomerID    Field1    Field2    ....
   1             5          ...       ...
   1             15         ...       ...

Table2
CompanyID    CustomerID    Field1    Field2    ....
   10           125         ...       ...
   10           145         ...       ...

Which will all go into a single database:

Destination DB  
CompanyID    CustomerID    Field1    Field2    ....   
   1              5          ...       ...  
   1              15         ...       ...    
   1              27         ...       ... 
   5              15         ...       ... 
   10             125        ...       ...
   10             145        ...       ... 
   11             100        ...       ...

So, in this case I would delete from the destination table the items that match from tables 1 & 2. The destination database will be growing constantly so creating a List of CustomerID does not seem feasible. However, I expect daily imports of new and updated customer info to be relatively small (in the hundreds, maybe near 1000 records).

If I cannot write a single join what other method for completing this process would be appropriate? I am trying to figure something out since it looks like I cannot actually mix Linq-to-Sql and Linq-to-Objects.

Is it possible to somehow map my data table to the entity datamap, tbl_CustomerInfo, filling an otherwise immutable var, then perform the join?

Update

Here is what I have accomplished at this point and I get the results I expect from dupes:

using (DataContext context = new DataContext(SqlConnection)
{
    var custInfo = context.GetTable<tbl_CustomerInfo>();

    string compID = ImportCust.Rows[0]["CompanyID"].ToString();

    var imports = from cust in ImportCust.AsEnumerable()
                  select cust.Field<int>("CustomerID");

    var dupes = from cust in custInfo
                join import in imports
                on cust.CustomerID equals import
                where cust.CompanyID == compID
                select cust;

    custInfo.DeleteOnSubmit(/* what goes here */);
    context.SubmitChanges();
}

My question now is, what goes into the DeleteOnSubmit(...)? I feel like I have gotten so close only to be foiled by this.

  • 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-18T20:36:20+00:00Added an answer on May 18, 2026 at 8:36 pm

    I usually tackle all of this in a stored proc for efficiency.

    Add an identity field to your destination table to uniquely identify the records, then use a query like this:

    DELETE d
    FROM DestinationTable d JOIN (
       Select CompanyID, CustomerID, Min(UniqueID) AS FirstRecID
        FROM DestinationTable
        GROUP BY CompanyID, CustomerID) u on u.CompanyID=d.CompanyID AND u.CustomerID=d.CustomerID
    WHERE d.UniqueID <> u.FirstRecID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a process that extracts customer info from multiple databases (MySql) based on
I have Process objects that are monitored from two different views. A Windows.Forms.ListView (actually
I have a process that imports a lot of data (950k rows) using inserts
SOLUTION BELOW We have an ETL system that extracts data into a CSV, uploads
We have a process that is getting data in real time and adding records
I have a Process from within Weblogic 10.3 that takes in an XmlObject, writes
I have an ETL process that is, for this question's purpose, done entirely in
I developed a Word 2003 report generation application that extracts data from a database.
I have this build process that create rpms for a set of linux distributions.
We have a number of DTSX Packages that Extract-Transform-Load data from a number of

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.