compiled-query

LINQ-to-SQL Compiled Query Problem (works as uncompiled query)

Hello, I have C# extension methods on IQueryable, e.g. FindNewCustomers() and FindCustomersRegisteredAfter(int year) and so forth which I use to "chain" a query together for LINQ to SQL. Now to my problem: I want to create compiled queries, e.g.: private static Func<MyDataContext, SearchInfo, IQueryable<Customer>> CQFindAll ...

Dynamic Order (SQL ORDERBY) in LINQ CompiledQuery

Hello, how can I create a dynamic ORDERBY in my LINQ CompiledQuery (e.g. supply Order Field and Direction as parameters for the compiled query)? ...

Use Inline Table Valued Function in LINQ Compiled Query

Is it possible to create a LINQ compiled query that utilizes an ITVF (inline table valued function)? ...

How to extract the Sql Command from a Complied Linq Query

In normal (not compiled) Linq to Sql queries you can extract the SQLCommand from the IQueryable via the following code: SqlCommand cmd = (SqlCommand)table.Context.GetCommand(query); Is it possible to do the same for a compiled query? The following code provides me with a delegate to a compiled query: private static readonly ...

Compiled LINQ query & DataLoadOptions... with a twist!

I know about the method discussed here: Solving common problems with Compiled Queries in Linq to Sql for high demand ASP.NET websites ... but this doesn't work for my situation as i get a : "Setting load options is not allowed after results have been returned from a query." I am using Codesmith PLINQO scripts to generate entities and...

Linq Compiled Queries and int[] as parameter

Hello , i'm using the following Linq to Sql compiled query. private static Func<MyDataContext, int[], int> MainSearchQuery = CompiledQuery.Compile((MyDataContext db, int[] online ) => (from u in db.Users where online.Contains(u.username) select u)); I know it is not possible to use sequence input pa...

Compiled query returns the same thing every time

I have this compiled query: private static Func<DBContext, Foo> FooQuery = CompiledQuery.Compile<DBContext, Foo>( _db => _db.FooTable.SingleOrDefault(f => f.DeletionDate == null || f.DeletionDate > DateTime.UtcNow) ); When I run it once, it returns the expected Foo object. But then, even after that object's DeletionDate is set in...

Why can't you return a List from a Compiled Query?

I was speeding up my app by using compiled queries for queries which were getting hit over and over. I tried to implement it like this: Function Select(ByVal fk_id As Integer) As List(SomeEntity) Using db As New DataContext() db.ObjectTrackingEnabled = False Return CompiledSelect(db, fk_id) End Using End Functio...

Linq-to-sql Compiled Query returns object NOT belonging to submitted DataContext ?

Compiled query: public static class Machines { public static readonly Func<OperationalDataContext, short, Machine> QueryMachineById = CompiledQuery.Compile((OperationalDataContext db, short machineID) => db.Machines.Where(m => m.MachineID == machineID).SingleOrDefault() ); public s...

LINQ compiled query DataBind issue

Hello All, I have a pretty extensive reporting page that uses LINQ. There is one main function that returns an IQueryable object. I then further filter / aggregate the returned query depending on the report the user needs. I changed this function to a compiled query, it worked great, and the speed increase was astonishing. The only pr...

Why doesn't this CompiledQuery give a performance improvement?

I am trying to speed up an often used query. Using a CompiledQuery seemed to be the answer. But when I tried the compiled version, there was no difference in performance between the compiled and non-compiled versions. Can someone please tell me why using Queries.FindTradeByTradeTagCompiled is not faster than using Queries.FindTradeByTr...

Entity Framework - Using a list as a paramater in a compiled query

Hi guys Just wondering if anyone knows whether I should be able to pass in list into a compiled query and have the query perform a contains operation? The reason why I ask is that I have a scenario where I need to do this, yet at run time I am getting the following error... The specified parameter 'categories' of type 'System.Collect...

Linq To Sql: Compiled Queries and Extension Methods

Hi community, I'm interessted, how does Linq2Sql handles a compiled query, that returns IQueryable. If I call an extension method based on a compiled query like "GetEntitiesCompiled().Count()" or "GetEntitiesCompiled().Take(x)". What does Linq2Sql do in the background? This would be very bad, so in this situation I should write a compi...

Entity framework 4.0 compiled query with Where() clause issue

Hello, I encountered with some strange behavior of System.Data.Objects.CompiledQuery.Compile function - here is my code for compile simple query: private static readonly Func<DataContext, long, Product> productQuery = CompiledQuery.Compile((DataContext ctx, long id) => ctx.Entities.OfType<Data.Product>().Where(p => p.Id ...

Entity Framework 4 simple Compiled Query internal exception on compilation

I want to retrieve one page from a sorted table. I want the sorting and paging to be done on the server. For this I created the following compiled query: internal static readonly Func<MyEntities, string, int, int, IQueryable<Model.Message>> MessagesPagedSortedByDateQuery = CompiledQuery.Compile((MyEntities db, string folderId, i...

Switch statement in compiled query possible?

Is it at all possible to use something like a switch statement in a compiled query for linq to entities/sql? For example when returning sorted records from the database, I would like to use a switch-like statement within one compiled query to sort on different properties, instead of having to write 2 compiled queries (ascending & descend...

LINQ-to-SQL "Member access not legal on type" exception with unioned and compiled query

I have multiple queries that I'd like to union together, then compile the entire thing. The uncompiled query runs fine, but an "InvalidOperationException: Member access 'Int32 Id' of 'UserQuery+Foo' not legal on type 'System.Linq.IQueryable`1[UserQuery+Foo]." exception is thrown when the same query is compiled and run. How do I fix thi...

Which methods to close a compiled query

As we know you can't add an extra clause like .Where() or .First() to a compiled query, because that changes the query and forces a recompile. What I would like to know is which methods can be used to "close" a compiled query. I know most people use either .AsEnumerable() or .ToList(), but which other methods work as well? Can I use .A...

Compiled query with DBLinq

Is it possible to create compiledQuery with DBLinq? ...

Do we still need stored procedures when using compiled queries?

When using compiled queries in entity framework (or linq-to-sql) in combination with SQL Server, is there actually still any performance benefit in using stored procedures? Compiled queries will be cached as parameterized queries, so performance should be near equal to stored procedures. Is there any situation where stored procedures wo...