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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:09:30+00:00 2026-05-24T20:09:30+00:00

Are these two blocks exactly the same? Does one have any advantage over the

  • 0

Are these two blocks exactly the same? Does one have any advantage over the other?

        using (var context = new TRANSITEntities())
        {
            var result = context.Table1.Where(c => c.UserCode == "123");
        }


        using (var context = new TRANSITEntities())
        {
            var result = from c in context.Table1
                         where c.UserCode == "123"
                         select c;
        }
  • 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-24T20:09:31+00:00Added an answer on May 24, 2026 at 8:09 pm

    Exactly the same.

    You can verify this yourself by looking at the ToString()

        string query1String, query2String;
        using (var context = new TRANSITEntities())
        {
            var result = context.Table1.Where(c => c.UserCode == "123");
            query1String = result.Expression.ToString();
        }
    
    
        using (var context = new TRANSITEntities())
        {
            var result = from c in context.Table1
                         where c.UserCode == "123"
                         select c;
            var query2String = result.Expression.ToString();
        }
    
        Assert.AreEqual(query1String, query2String);
    

    It should also be noted that result is NOT actually a result. It’s a non-executed/enumerated IQueryable. Meaning it’s like a SQL statement that hasn’t been run yet (sort of). If you were to do

        var t1 = result.ToArray()
        var t2 = result.ToArray()
    

    then the query would actually be executed twice. t1 and t2 are the REAL results (an in memory array)…not result. In other words, result should really be named query And further, the example you have above will never work…because if you call ToArray on the result outside of the using block, it will fail…because you can’t run the query once the context is disposed:

        using (var context = new TRANSITEntities())
        {
            var result = context.Table1.Where(c => c.UserCode == "123");
        }
        // throws exception:
        var array = result.ToArray();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can I combine these two blocks into one: Edit: Any other method than combining
Do these two keywords have exactly the same effect, or is there something I
Are there any significant performance differences these two blocks of code? var element =
These two may look like they have no correlation but bear with me! In
These two methods appear to behave the same to me public IEnumerable<string> GetNothing() {
These two querys gives me the exact same result: select * from topics where
Can these two SVN clients collaborate? I have my projects checked out with Tortoise,
I have two web applications running in same Servlet container ( Tomcat ), A
I have two devices - HTC Tattoo and Sony Ericsson Xperia X10. One has
I have two tables: block: int id, [other columns...] blockInstance: int id, int blockId

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.