Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding a where/order by clause to an IQueryable
    primarykey
    data
    text
    <p>I have ths function to query a set of records from the DB:</p> <pre><code>public IQueryable&lt;PointTransactionViewModel&gt; GetPointTransactions(int UserID) { return ( from PointTransaction p in entities.PointTransaction join ActivityLog a in entities.ActivityLog on p.TransactionID equals a.TransactionID where p.UserID == UserID select new PointTransactionViewModel { ID = p.TransactionID, Balance = p.Balance, Points = p.Amount, RelatedActivityID = a.ID, When = p.When, Sender = p.SenderUserInfo.CompleteName } ); } </code></pre> <p>I wish to add an additional cause, like this</p> <pre><code>var entries = GetPointTransaction(1); return entries.OrderbyDescending.Where( x =&gt; x.When &gt;= start &amp;&amp; w.When &lt;= end). ( x =&gt; x.When); </code></pre> <p>However, I seem to need to create a new query from the existing one for this to work. But, I have seem this work before without creating a new query, in the code snippet before:</p> <pre><code> public PaginatedList(IQueryable&lt;T&gt; source, int pageIndex, int pageSize) { PageIndex = pageIndex; PageSize = pageSize; TotalCount = source.Count(); TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize); this.AddRange(source.Skip(PageIndex * PageSize).Take(PageSize)); } </code></pre> <p>Does the code above somehow doesn't need a new query to be created for the IQueryable source object? Was a temporary object created?</p> <p><strong>Edit</strong></p> <p>It's strange, but to get it to work I have to do the following:</p> <pre><code>IQueryable&lt;ActivityLogEntry&gt; log = activityRepo.GetPointTransaction(userID). Where(x =&gt; x.PointsEarned == 50); return log.ToList(); </code></pre> <p>The following will not work:</p> <pre><code>var log = = activityRepo.GetPointTransaction(userID); log.Where( x =&gt; x.PointsEarned == 50); return log.ToList(); </code></pre> <p>There is no error message, just that the where clause seems to be ignored (it is also returning all data which PointsEarned is not 50)</p>
    singulars
    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.
    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