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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:36:46+00:00 2026-06-16T16:36:46+00:00

Suppose I have a DataContext object and access two tables at the same time:

  • 0

Suppose I have a DataContext object and access two tables at the same time:

using( var context = new DataContext( connectionString ) ) {
     foreach( firstTableEntry in context.GetTable<FirstTable>() ) {
         switch( firstTableEntry.Type ) {
         case RequiresSecondTableAccess:
         {
             var secondTable = context.GetTable<SecondTable>();
             var items = secondTable.Where( item => item.Id = firstTableEntry.SecondId );
             foreach( var item in items ) {
                handleItem( item );
             }
         }
         default:
           // not accessing the second table
     }
}

Note that I don’t stop using the first query results while making queries to the other table and use the same DataContext object all the time.

Is such usage legal? Should I expect any problems with this approach?

  • 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-16T16:36:47+00:00Added an answer on June 16, 2026 at 4:36 pm

    This will only work if you have support for Multiple Active Recordsets (MARS) in your database engine. If not, you will generate an exception. Otherwise, you can definitely do this.

    If you do not have MARS support, you will need to use .AsEnumerable to download all records from the database at one time and convert to an in-memory enumerable.

    Here’s another great resource on what in Entity Framework uses MARS and what you can’t do if you don’t have it.

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

Sidebar

Related Questions

Suppose I have a UserControl whose DataContext is set to an object that has
Suppose I have two tables, - emp(empId number(1),empName varchar2(50)) and - manager(manId number(5),managerName varchar2(100))
Here's the situation: Using WPF I have an object set to the DataContext of
Suppose I have a dataset with those two immortal tables: Employee & Order Emp
Suppose I have a static method of my class that returns an object of
Suppose I have two table tab1, tab2. EF will create a edmx file and
Suppose I have a view with the following control (DataContext is properly set to
I have two tables, in which one user can have several contacts: User(UserId, UserName)
Suppose I have two pages: - page 1 uses jquery mobile and has a
Suppose you have val docs = List(List(one, two), List(two, three)) where e.g. List(one, two)

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.