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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T16:48:19+00:00 2026-05-17T16:48:19+00:00

I was looking through the sample LINQ queries provided with LINQPad taken from the

  • 0

I was looking through the sample LINQ queries provided with LINQPad taken from the C# 4.0 in a Nutshell book, and ran across something I have never used in LINQ to SQL… Compiled Queries.

Here is the exact exmaple:

// LINQ to SQL lets you precompile queries so that you pay the cost of translating
// the query from LINQ into SQL only once. In LINQPad the typed DataContext is
// called TypeDataContext, so we proceed as follows:

var cc = CompiledQuery.Compile ((TypedDataContext dc, decimal minPrice) =>    
    from c in Customers
    where c.Purchases.Any (p => p.Price > minPrice)
    select c
);

cc (this, 100).Dump ("Customers who spend more than $100");
cc (this, 1000).Dump ("Customers who spend more than $1000");

What does precompiling a LINQ to SQL query like this actually buy me? Would I get a performance boost from a query slightly more complex than this one? Is this even used in actual practice?

  • 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-17T16:48:19+00:00Added an answer on May 17, 2026 at 4:48 pm

    In a nutshell, precompiled querires buy you a performance gain when you need to run a single query multiple times.

    Here’s some information on LINQ To SQL performance.

    I’ve read in several places that
    compiling your LINQ will help, but I
    have never heard anyone say how
    drastic the speed improvement can be.
    For example, in one of my favorite
    books (LINQ in Action) by Fabrice
    Marguerie and others, he quotes on
    page 296 a blog post by Rico Mariani
    titled DLINQ (Linq to SQL Performance
    (Part 1) as saying using a compiled
    query offers nearly twice the
    performanced of a non-compiled query,
    and goes on to say that it brings the
    performance to within 93% of using a
    raw data reader. Well, suffice it to
    say I never ran the test myself. I
    could have lived with twice, but not
    37 times.

    alt text

    So, from this, it seems that you
    should always compile your LINQ to SQL
    queries. Well, that’s not quite true.
    What I’m recommending is that if you
    have a reason to execute the same
    query over and over you should
    strongly consider compiling. If for
    example, you are just making a LINQ to
    SQL call once, there is no benefit
    because you have to compile it anyway.
    Call it ten times? Well, you will
    have to decide for yourself.

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

Sidebar

Related Questions

I was looking through the sample gwt code provided with gwt, and in hacking
While looking through some old code I came across this gem: MyObject o =
I was looking through the Domain Oriented N-Layered .NET 4.0 Sample App project and
So I was looking through some sample code in Script#'s samples. I noticed that
I have been looking through this fantastic article: http://blogs.zynaptiq.com/bernsee/pitch-shifting-using-the-ft/ While being fantastic, it is
Looking through multiple iOS crash logs, I'm finding stack traces which are near identical
Looking through decimal.py , it uses NotImplemented in many special methods. e.g. class A(object):
Looking through a few SQL implementations, I noticed that most DBMSs support defining an
Looking through the documentation for CFDataRef I can't see anything that will compress a
Looking through the massive android source code, anyone on here who know where exactly

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.