Sometimes Case Insensitivity is a bit Overkill

I’m working on a set of code that requires that I synchronize some data fields between my modern Microsoft SQL Server 2005 instance, and our ancient ADABAS-based mainframe database. There are two circumstances where I need to validate this information, the first, is when I need to validate that data has been entered into the mainframe correctly (currently, this entry is being done by hand, we’re lobbying for a programmatic method), and the second is when I need to reimport the results of a particular task that modifies the mainframe, but not my own system.

However, I ran into a fairly bizarre issue related to how C#, LINQ, and SQL Server all operate. For one particular course, a text field was set defining the title of the course as ‘Ballet’. Since the ADABAS doesn’t support lower-case characters this got entered into the mainframe as ‘BALLET’. It’s minor, and forcing the word to capital in our system shouldn’t have been a problem, so during the reimport, I allow such things to be “corrected”.

However, during the import, this particular change resulted in a LINQ Exception. It didn’t think the row had changed, and therefore threw an exception when I tried to update it.

var masterSection = (from m in writer.MasterSections
                                        where m.Id == secInfo.MasterSectionId
                                        select m).Single();

masterSection.Title = ssData.SectionTitle;
writer.SubmitChanges();

ssData is the collection of data from the Mainframe, which I’ve queried using other tools. As I say above, this would consistently throw an exception, claiming that there were no changes to commit. Eventually, I ended up assigning this:

var masterSection = (from m in writer.MasterSections
                                            where m.Id == secInfo.MasterSectionId
                                            select m).Single();

if (!masterSection.Title.Equals(ssData.SectionTitle, StringComparison.OrdinalIgnoreCase)) {
    masterSection.Title = ssData.SectionTitle;
    writer.SubmitChanges();
}

It’s really important to note that the Equals call requires an IgnoreCase flag. Without it, C# sees the two strings as being different, and will continue to except on this SubmitChanges call. But, I thought to myself, isn’t ‘Ballet ’ and ‘BALLET ’ different? Apparently not, at least in Microsoft SQL Server.

SELECT CASE WHEN 'Test ' = 'TEST ' THEN 1 ELSE 0 END;

Execute that query in SQL Server, and you will get the value 1 in the result set. I’m going back and forth on this issue. It seems to me that this is a bug, but I’m not sure how many would agree. Any opinions?