I need help trying to combine two IEnumerable queries. Both queries work fine separately, but I need to find a way to combine them.
One query returns results that contains all physical books that can be seen by the current user.
The second query returns all digital books that can be seen by the current user.
Really, I just need one query that returns both physical and digital books that can be seen by the current user.
The problem is that I need to use a different method to check user permissions for each book type and I can't change that part.
Thanks!
var user = AllUsers.Current;
var BookFetchResults = rows.Select(r => new SearchResult(r))
.Where(t => t.BookType == "Physical")
.Select(r => r)
.Where(e => e.CanViewPhysical(e.PhysicalBookResult, user) );
return Ok(results);
var BookFetchResults = rows.Select(r => new SearchResult(r))
.Where(t => t.BookType == "Digital")
.Select(r => r)
.Where(e => e.CanViewDigital(e.DigitalBookResult, user) );
return Ok(results);
You can do all of that in query Where statement:
var BookFetchResults = rows.Select(r => new SearchResult(r))
.Where(t => (t.BookType == "Physical" && t.CanViewPhysical(e.PhysicalBookResult, user)) ||
(t.BookType == "Digital" && t.CanViewDigital(t.DigitalBookResult, user));
You do realize that the lines .Select(r => r)
do nothing? All that lines is return the same value that is input. You only need to do a select if your are changing the type, like you do in .Select(r => new SearchResult(r))
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With