by scarface74 · 7y ago · 0 comments
For instance in C# you can take the same LINQ expressions and they can be translated to sql by EF or MongoQuery by the Mongo driver at runtime.
var retiredMales = custRepo.Find(c => c.Age > 65 and c.Sex == “M”)
and then have an interface with a member:
List<Customer> Find(Expression<Func<Customer,bool>> expression):
You can implement three classes for that interface - one that uses EF, one that uses Mongo, and one that just uses in an memory List for unit testing and they all translate the expression to the underlying data store.
Theoretically, you could have an “expression” type in JS that can be parsed by the provider.
For those who gave never used linq: this allows the above function to translate the function to a sql, sparql or mongo query depending on the currently selected backend