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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:05:29+00:00 2026-05-14T04:05:29+00:00

for example I’m trying to get the data from database like: using (ExplorerDataContext context

  • 0

for example I’m trying to get the data from database like:

using (ExplorerDataContext context = new ExplorerDataContext())
        {
            ObjectQuery<Store> stores = context.Store;
            ObjectQuery<ProductPrice> productPrice = context.ProductPrice;
            ObjectQuery<Product> products = context.Product;
            res =
                from store in stores
                join pp in productPrice
                on store equals pp.Store
                join prod in products
                on pp.Product equals prod
                select store;
        }

After this code I cannot transfer the result to some another method because the context doesn’t exist more. How could I get the unlinked result independent on the context?
Thanks

  • 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-14T04:05:29+00:00Added an answer on May 14, 2026 at 4:05 am

    Materialize the query by calling ToList() on the result. This will run the query and convert the results to a List of the object. Since List<T> implement IEnumerable<T>, this should still work if you’ve declared your variable as IEnumerable<Store>.

        using (ExplorerDataContext context = new ExplorerDataContext()) 
        { 
            ObjectQuery<Store> stores = context.Store; 
            ObjectQuery<ProductPrice> productPrice = context.ProductPrice; 
            ObjectQuery<Product> products = context.Product; 
            res = 
                (from store in stores 
                join pp in productPrice 
                on store equals pp.Store 
                join prod in products 
                on pp.Product equals prod 
                select store).ToList(); 
        }
    

    LINQ (to SQL) works by building up an Expression tree that represents the query. Until the query is actually enumerated (or explicitly materialized by calling a method like ToList()), the query hasn’t been performed. You need to make sure that the query is performed before the context is disposed. The quickest way to do that, given the code you show, is calling ToList(). You could, perhaps, also just extend the context scope to cover your usage, but if you are supplying the data to a view (web page), that’s not likely to be effective. In other contexts, however, it might be possible — say to just include the enumeration of the query inside the using block of the context.

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

Sidebar

Related Questions

Example from Using YAML with Python Original YAML file contains this # tree format
Example: batchTag is an enumerated type attribute of a batchRange, with values like so:
Example: select * from component inner join component_supplier on component.id = component_supplier.component_id inner join
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Example: error_reporting(E_ALL | E_STRICT); class Test {} $obj = new Test(); $obj->undeclared = oops;
Example output from PHP: { RootName_0:{Id:1,ValId:1,Value:Colour,Text:Blue}, RootName_1:{Id:1,ValId:2,Value:Colour,Text:Red} } How can I use Backbone.js or
I am trying to render a haml file in a javascript response like so:
Example: public abstract class BaseControler : Controller { public IUnitOfWork UnitOfWork { get; set;
Example: <select id=myselect> <option value=A>First</option> <option value=B>Second</option> <option value=C selected=selected>Third</option> <option value=D>Fourth</option> </select> Using
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.