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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:11:31+00:00 2026-05-22T23:11:31+00:00

I have related data living on two completely separate databases, and I need information

  • 0

I have related data living on two completely separate databases, and I need information from both of these databases. One of the databases lives on a MySql server and the other one lives on a MS SQL Server. Don’t ask why we have related data living on two completely different servers, it’s a long story.

From a high-level perspective, I need to join MySqlTableA to SQLServerTableB, do some complex restrictions, and possibly do some GROUP BYs and counts.

I’m trying to find a way to make joining between these two databases reasonably easy. I thought LINQ might solve my problems, but I can’t create a single context that has both MySql and SQL Server sources, as far as I know. I can put the two sources in different contexts — using Devart’s LinqConnect to create a MySql context — but LINQ doesn’t allow cross-context joins. (I tried the method described here, but it didn’t work: Simulating Cross Context Joins–LINQ/C#)

So what are my options? Is there a way to efficiently join tables on these two different database servers (though LINQ or otherwise), or am I going to have to loop through and join the data by hand?

EDIT:

As mentioned, I’ve already tried the AsQueryable() workaround, but I still get a cross-context exception. Here is my code:

public static MySqlDataContext mysql = new MySqlDataContext();
public static SQLDataContext sql = new SQLDataContext();

public static void Main() {
    var rows = from a in mysql.tableA
               join b in GetTableBs() on a.col equals b.col
               select a;

    //exception gets thrown when rows is enumerated.
    //InvalidOperationException: "The query contains references to items defined on a different data context."
    foreach(var row in rows) {
        ...
    }
}

public static IEnumerable<TableB> {
    return sql.TableBs.AsQueryable();
}
  • 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-22T23:11:32+00:00Added an answer on May 22, 2026 at 11:11 pm

    I have performed a test using latest dotConnect for MySQL and Entity Developer for SQL Server and succeeded in implementing the workaround as in the following example:

      var join = from d in GetDepts()
                 from e in db1.Emps
                 select new {
                   e.ENAME,
                   d.DNAME
                 };
      join.ToList();
    }
    public IEnumerable<DEPT> GetDepts() {
      return db.DEPTs.AsQueryable();
    }
    

    Could you please send us a small test project illustrating the problem?
    Update.The previous “cross-join” solution is actually not very appropriate.
    The better solution is to materialize both collections and then perform an in-memory join of materialized objects:

    public static MySqlDataContext mysql = new MySqlDataContext();
    public static SQLDataContext sql = new SQLDataContext();
    
    public static void Main() {
      var qA = mysql.tableA.ToList();
      var qB = sql.TableBs.ToList();
      var rows = from a in qA
                 join b in qB on a.col equals b.col
                 select a;
    
      foreach(var row in rows) {
          ...
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got a table containing rows of related data which I need to
Ok so at work we have discovered that this method to fetch related data
I have created a stored procedure to delete data from multiple tables. my work
Group of related data like a list of parts etc., can be handled either
The Problem We have a large web application that stores and displays sensitive HIPAA-related
I have a custom module, in which I want to load some use related
I have an Two table, main table is Invoice and sub table is Invoice_split.
I have an slightly unusual security requirement, and I'm looking for advice on best
I made a mistake when using Leaks instrument that I thought total living objects
My Question is can we extend one context to another in Entity Framework 4.

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.