title: Query Performance for multiple IQueryable in .NET Core with LINQ
body: <p>I am currently updating a BackEnd project to .NET Core and having performance issues with my Linq queries.</p>
  
  <p>Main Queries:</p>
  
  <pre><code>var queryTexts = from text in _repositoryContext.Text
                           where text.KeyName.StartsWith("ApplicationSettings.")
                           where text.Sprache.Equals("*")
                           select text;
  
  var queryDescriptions = from text in queryTexts
                                  where text.KeyName.EndsWith("$Descr")
                                  select text;
  
  var queryNames = from text in queryTexts
                           where !(text.KeyName.EndsWith("$Descr"))
                           select text;
  
  var queryDefaults = from defaults in _repositoryContext.ApplicationSettingsDefaults
                              where defaults.Value != "*"
                              select defaults; 
  </code></pre>
  
  <p>After getting these IQueryables I run a foreach loop in another context to build my DTO model:</p>
  
  <pre><code>foreach (ApplicationSettings appl in _repositoryContext.ApplicationSettings)
  {
    var applDefaults = queryDefaults.Where(c =&gt; c.KeyName.Equals(appl.KeyName)).ToArray();
  
    description = queryDescriptions.Where(d =&gt; d.KeyName.Equals("ApplicationSettings." + appl.KeyName + ".$Descr"))
                  .FirstOrDefault()?
                  .Text1 ?? "";
  
    var name = queryNames.Where(n =&gt; n.KeyName.Equals("ApplicationSettings." + appl.KeyName)).FirstOrDefault()?.Text1 ?? "";
  
    // Do some stuff with data and return DTO Model
  }
  </code></pre>
  
  <p>In my old Project, this part had an execution from about 0,45 sec, by now I have about 5-6 sec..</p>
  
  <p>I thought about using compiled queries but I recognized these don't support returning IEnumerable yet. Also I tried to avoid Contains() method. But it didn't improve performance anyway.</p>
  
  <p>Could you take short look on my queries and maybe refactor or give some hints how to make one of the queries faster?<br>
  It is to note that <code>_repositoryContext.Text</code> has compared to other contexts the most entries (about 50 000), because of translations.</p>