Every IQueryable
holds an Expression
and a Provider
. The Expression
holds the query that must be performed. The Provider
knows who has to execute the query, usually a database management system. It is the task of the Provider
to translate the Expression
into the language that the database understands (something SQL-like) and to execute the query. The Provider
will fetch the results in an efficient way and return the queried data as an enumerable object.
The IQueryable
implements IEnumerable
.
When you use LINQ functions like ToList()
, FirstOrDefault()
, Any()
, or use the query in a foreach
, then internally IEnumerable.GetEnumerator()
is called and Enumerator.MoveNext()
This will order the Provider
to translate the Expression
into SQL and execute the query. The returned enumerable is used to enumerate over the returned items.
It is the task of the programmer of the class that implements the IQueryable
to implement the translation of the Expression
into SQL. This is not easy, and I think the people who created entity framework did a great job.
However, some items known in SQL are very difficult to implement. Among those are the notions of SoundEx and Difference. I'm not sure, but I think that one of the reasons that made this difficult is that they are typically something used in SQL, and not in any other kind of IQueryable systems.
In fact, there are a several functions that are not supported by entity framework. See Supported and unsupported LINQ methods (LINQ to entities).
Your DbContext is an abstract representation of your database model. Users of it should not care whether it uses Microsoft SQL, MySQL, or whether it is a data collection that doesn't use anything similar to SQL.
But if you are absolutely certain that it is okay to limit your DbContext to only a certain kind of databases, one that knows the concepts of SoundEx and Difference, consider creating a stored procedure for your query. See How to call a Stored Procedure in Entity Framework