Quantcast
Channel: entityframework Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1793

New Post: Performance issue with single value constant.

$
0
0
We are creating expressions like this:
var one = new int[] { 0 };
var result = (from t in Table
  select new TableModel() 
  {
    Name = t.Name,
    List = (from o in one where t.SomeValue != null select t.SomeValue),
  }
);
The exact reasons for this are beyond the scope of this question, but basically we have a few places where we need a single value turned into a list with EF to SQL. Sometimes we even concat a bunch of these together. So we join against a hard-coded single value list and all is well.

Except that Entity Framework insists on recompiling the query every time it is executed, bypassing the query cache. I found the source of this in System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.ConstantTranslator:

// Invalidate the query plan every time the query is executed since it is possible
// to modify an element of a collection without changing the reference.
parent._recompileRequired = () => true;
I'm racking my brain trying to figure out a way around this. EF doesn't seem to expose the SingleRowTable anywhere that can be used.

Any ideas?

Viewing all articles
Browse latest Browse all 1793

Trending Articles