Linq-to-Entities match ID in list of integers in a compiled query?

I ended up finding a way to do it but it's way too slow at around 3s. String ids = "|" + String. Join("|", new List { 4, 5, 6, 7, 8, 9, 10, 20, 23, 34 }) + "|"; Func> query = System.Data.Objects.CompiledQuery.

Compile( (MyEntities entities, string IDs) => ( (from au in entities. Mine where IDs. Contains("|" + SqlFunctions.

StringConvert((decimal)au. ID).Trim() + "|")select au) )); Back to the drawing board.

You can't. What does CompiledQuery do? It pre-converts the query to a canonical command tree -- an intermediate representation used to generate SQL by the provider.

The SQL for a command with a scalar param is the same structure regardless of the param value. But the SQL generated for, say, a list of 2 items will be structurally different from the SQL afor a list of 3 items, because it takes one fewer OR predicate in its WHERE clause. Most DB servers won't take lists as a param value, after all.

Your string/| kludge works because you're now passing only one param, not a list, to the DB server. But as you've seen, the server can't index such a query, so it will be slow.

It pre-converts the query to a canonical command tree -- an intermediate representation used to generate SQL by the provider. The SQL for a command with a scalar param is the same structure regardless of the param value. But the SQL generated for, say, a list of 2 items will be structurally different from the SQL afor a list of 3 items, because it takes one fewer OR predicate in its WHERE clause.

Most DB servers won't take lists as a param value, after all. Your string/| kludge works because you're now passing only one param, not a list, to the DB server. But as you've seen, the server can't index such a query, so it will be slow.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions