views:

101

answers:

1

I see a lot of posts of people using compiled Linq to Sql queries for high-demand asp.net applications. I've done some performance tests and in many cases compiled queries are better than the ordinary ones. What bothers me is that when using compiled queries the query is preserved in a static variable. In asp.net in many cases it is not safe to use static variables. I know that it is actually a static delegate instance but still is it safe to use it that way?

+4  A: 

What makes you think it's not safe to use static variables in ASP.NET? You shouldn't use mutable static variables (without care, anyway), but a compiled query isn't mutable in itself, so it's fine so long as you either make the variable readonly or take appropriate care when changing its value.

Jon Skeet