When the query variable is declared, it seems that it is getting all items in the table (image 1),
It's not
I'm I missing something to use deferred execution?
You are
Here's a screenshot from a test app after I turn logging on. In the code of the test app I create a context, build a query, and run it.. A couple of times in fact..

x is the context. If I open the debugger and expand the Orders "table" in the debugger tooltip there's a message at the bottom saying that looking at the results will enumerate the enumerable. If I enumerate, then the SQL will be executed:

There aren't any clauses on this - we're enumerating Orders which represents the entire table, so the SQL run is effectively SELECT * FROM Orders. There isn't any data in my Orders test table, which is why we see "no results" after the enumeration is complete, but if there were 1000 orders the debugger tooltip would have 1000 items in
The next line of code runs a LINQ Where:

This hasn't actually executed any SQL, but it's supplied a clause that EF can translate to SQL, so if you take a look in the DebugView property of the IQueryable returned by the Where, you can see the SQL that EF will form (...WHERE Ref = '') when it's run.
Enumerating the queryable would actually run the SQL. Calling for a Results View in the debugger would enumerate, as would doing something like ToArray, ToList, ToDictionary (internally they all enumerate), or even a plain old foreach etc on your queryable. Whenever there's an enumeration, it triggers the running of the SQL.
If you use something like First, Count, Single then these trigger the execution of the SQL query also; they don't enumerate the entire set, they modify the SQL that is run but they do cause execution..
..which brings me to the point raised in the comments.
The code I've written enables EF to form a query with a WHERE clause, but then it asks the DB to execute it twice: once to get the Count (calling .Count causes a SELECT COUNT(*) ... WHERE ..) and then again to get the actual data items (calling ToList does a SELECT columns ... WHERE ...`):

Given that you have to retrieve e.g. 100 items during the enumeration it would make more sense to retrieve them all and then get the local count of them; if you've stashed them in a list then the list will be tracking the Count
Keep in mind that when you're working with EF's sets and you haven't done anything to enumerate them already, the queryable you;re passing around and calling operations on essentially represents an SQL (or a partly built one) and every time you do something to it that will deliver data, it'll run the SQL
IQueryables when viewed in debug mode. If I'm not mistaken, during runtime it shouldn't query until you get the count.Cast<Country>()call when you already have aIQueryable<Country>instance?querydoes not fetch the whole content of the table. The rows are only retrieved when the query is executed/iterated. So your code should already do what you are planning to do. If it doesn't, add a minimal reproducible example which shows the problem you have.castis not necessary. And thank you for the answer, I've missed that little information @IvanStoev.