Little Things that make a difference. Part II. DA LINQ String Operations
One thing that DA LINQ lacked until recently was support of the string data comparison operations. This means that there was no easy way to properly express SQL statement like:
SELECT Id, Name FROM dbo.Customers WHERE Name > 'Alpha'
using DA LINQ. Even worse – a lot of .NET languages don’t support ** or > operators with sting operands. This means that, for example, C# cannot compile code like:**
bool r = "A" > "B";
Of course there are a lot of ways to compare strings in .NET, but to use them, you first have to load the data into the client app using DA LINQ and then filter that data locally using Linq2Objects. Obviously, an approach like this is not always feasible, especially on big datasets or slow network connections.
So a different way to express string comparison operations was needed. Data Abstract was recently expanded with a set of extension methods allowing to express string comparison operations in DA LINQ queries like for example:
var data = from x in dataAdapter.GetTable<customers>() where x.Name.IsGreaterThan("Alpha") select x;
These extension methods provide enough information for the internal magic of DA LINQ to construct proper SQL statements.
The full list of supported string comparison operations is available on the corresponding docs page at http://docs.dataabstract.com/API/NET/StringExtensions_Class/.
Notice that while a set of .NET methods is used to express string comparison operations, the actual comparisons are still performed by the database. This has two implications:
- This feature will work only if sting comparison operations are supported at database level.
- String comparison results depend on database server collation settings.
Happy New Year!