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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:59:06+00:00 2026-05-18T08:59:06+00:00

The DataContext.GetTable() method will return an object of type: System.Data.Linq.Table By doing that, I

  • 0

The DataContext.GetTable() method will return an object of type:

System.Data.Linq.Table

By doing that, I presume I haven’t issued a call to the database to retrieve the entire table. Otherwise, LINQ would be somewhat inefficient.

Therefore, all I have done is drill into my strongly typed Datacontext class (eg, dbDataContext) to grab a handle on, for example, its “Customers” property, that represents the Customers table in SQL Server.

I can then get an IQueryable off the object returned by GetTable() and still not have hit the database. Ie, my ‘Service Layer’ code will be LINQ to Objects rather than Linq to Sql.

By doing all this, I will reduce the number of repositories that I need.

Question:

Are the above assumptions correct?

Note:

I am trying to figure out a way to build my Queries using interfaces and generics to make it testable and all that doo dah.

So, thinking along the lines of @zowen’s response to:

Repository pattern: One repository class for each entity?

I am trying to implement

public interface IQueryProvider<T>
{
     TResult Query<TResult>(Func<IQueryable<T>, TResult> query);
}

I know not strictly necessary, but I am going through the learning curve and looking at the architectural options that suit me and how I think.

What I’m trying to do:

I am trying to implement the following for SQL Server instead of MongoDb:

public class MongoQueryProvider<T> : IQueryProvider<T>
{
    private readonly IMongoCollection<T> collection;

    public MongoQueryProvider(IMongoDatabase database)
    {
        this.collection = database.GetCollection<T>();
    }

    public TResult Query<TResult>(Func<IQueryable<T>, TResult> query)
    {
        return query(this.collection.Linq());
    }
}

What I want is to get a handle on GetTable() and then write my Service Layer Linq code against that.

I suspect I will have to write a wrapper interface to get the equivalent of the IMongoDatabase database variable.

However, the question is the one above, not this other issue. Like I say, I’m just learning here. No production code will be hurt in this movie.

  • 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-18T08:59:06+00:00Added an answer on May 18, 2026 at 8:59 am

    The short answer to your question is that your assumptions are correct. You do not access the database through the GetTable<>() method of the DataContext. And, when you get an IQueryable you also don’t access the database until you enumerate on it.

    Also, see if this helps you on your quest: Advantage of creating a generic repository vs. specific repository for each object?

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

Sidebar

Related Questions

I can successfully connect to the database with my datacontext object. I am able
public tblCustomerDetail GetCustomerDetailsByID(long ID) { var customer = from c in DataContext.GetTable<tblCustomerDetail>() where c.ID
I have a process that extracts customer info from multiple databases (MySql) based on
As you know we use LinQ Technology to SQL Classes for send and get
I'm converting from LINQ to SQL to Entity Framework for my ORM and I'm
Using a code-first approach I'd like to map a single model to multiple table
I have a generic Repository implementation on top of Linq2SQL. Basically, it uses Table
I have this question for which I provided a solution. However, I don't feel
I'm following the fairly standard L2S repository pattern, using the following as one 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.