Note that there are some explanatory texts on larger screens.

plurals
  1. POCache a Linq Query - is this possible?
    primarykey
    data
    text
    <p>So, this may seem like an edge case, but I'm simply wondering if this is possible. What I have is a combination of a static set and deferred set wrapped in an <code>IEnumerable</code> - for example:</p> <pre><code>public IEnumerable&lt;T&gt; MakeMyQuery&lt;T&gt;() { // returns a List&lt;T&gt; var someStaticData = LoadMyStaticDataFromDatabase(); // Returns IEnumerable&lt;T&gt;, but from another resource var deferredQuery = CreateADeferredQueryUsingYieldReturn(); return someStaticData.Concat(deferredQuery); } </code></pre> <p>So what happens here is that when I call <code>.Take(someNumber)</code> on my enumerable, it will return elements from my static Data first before attempting to evaluate the deferred component - effectively, I have "hidden" some potentially time consuming producing tasks behind the enumerable such that if I never need to get those elements, they actually never get evaluated because of the deferred nature of LINQ. </p> <p>However, I don't think it's possible to cache this query for later use (I don't believe the state of the Iterator will be kept in cache, right?) Or is there an easy way to do this without enumerating the results to save?</p> <p>Ideally, my flow would be like so:</p> <pre><code>public List&lt;T&gt; SomeMethod&lt;T&gt;(int numberOfGuys) { IEnumerable&lt;T&gt; query = null; if(// Is in Cache) query = Cache["MyQuery"]; else { query = MakeMyQuery(); Cache["MyQuery"] = query; } return query.Take(numberOfGuys).ToList(); } </code></pre> <p>So I can re-use the same query over and over to request data, but potentially never have to requery the DB. Is there a way to do this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload