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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:45:57+00:00 2026-05-12T06:45:57+00:00

I currently have a LINQ query implemented as a method of my DataContext class.

  • 0

I currently have a LINQ query implemented as a method of my DataContext class. This method calculates the permissions a user has for a page within a Wiki/CMS. What I’d like to do is relocate this method to the Page and User LINQ data objects.

However, when I move this query to the individual data objects it executes using LINQ to Objects instead of LINQ to SQL. This means that it pulls several full collections from the database server every time it executes.

Here is a fragment of the code that uses LINQ to Objects. I’d like this to use LINQ to SQL:

partial class WikiPage
{
    public void GetUserPermissions(Guid? userId) {
        var usersPlusAnon =
            (
                from user in this.Wiki.WikiWikiUsers
                select new { user.WikiId, WikiUserId = (Guid?)user.WikiUserId }
            ).Union(
                from wiki in new Wiki[]{this.Wiki}
                select new { wiki.WikiId, WikiUserId = (Guid?)null }
            );
    }
}

Here is a fragment of the code that works, using LINQ to SQL. I’d rather have this method on the WikiPage class than the DataContext:

partial class WikiDataContext
{
    public void GetUserPermissions(Guid? userId) {
        var usersPlusAnon =
            (
                from user in this.WikiTomeUsers
                join wikiUser in this.WikiWikiTomeUsers on user.WikiTomeUserId equals wikiUser.WikiTomeUserId into tmp_wikiUser
                from wikiUser in tmp_wikiUser.DefaultIfEmpty()
                select new { WikiId = wikiUser.WikiId, WikiTomeUserId = (Guid?)wikiUser.WikiTomeUserId }
            )
            .Union(
                from wiki in this.Wikis
                select new { WikiId = wiki.WikiId, WikiTomeUserId = (Guid?)null }
            );
    }
}

When the LINQ query is run from the DataContext, it executes as LINQ to SQL, but when run from the WikiPage LINQ object it runs as LINQ to Objects. Is something off with my syntax here, or is this simply not possible with LINQ?

  • 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-12T06:45:57+00:00Added an answer on May 12, 2026 at 6:45 am

    The reason you are getting different behaviors from both sets of code is because you are using the ‘this’ keyword.

    When you write your code as part of the data context, it is using the LINQ to SQL classes in the DataContext object (because the ‘this’ keyword is pointing to the DataContext).

    If you want the code outside of the DataContext to use LINQ to SQL, you have to change your reference to ‘this’ to an instance of your WikiDataContext. It should then use LINQ to SQL to pull your data from the database rather than LINQ to Objects.

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

Sidebar

Related Questions

I currently have a query that looks like this: SELECT NON EMPTY ([Measures].[TOTAL]) ON
I currently have a LINQ query: public List<EventSchool> GetEventSchools(int eventID) { var eventSchools =
Currently I have a DataModel object which contains my linq to sql classes(a dmbl
I am currently learning C# and LINQ. I have lots of questions about them.
I currently have a need for a custom ListViewItem class - let's call it
I currently have links w/ class=ajax that I want to retrieve the element with
Okay so here's the thing: I have a linq query which loads approx. 1000
I have a linq query that needs to pull a date column out of
I have a LINQ query that returns all absences for an employee. The first
I have the following Linq to SQL query, in which I'm trying to do

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.