views:

115

answers:

2

Hello,

I have this piece of code:

fee.SingleOrDefault(f => 100.05M >= f.Rate);

In the database the Fee.Rate is a money field stored using invariant culture. But using this select gives an error because my current culture will convert "100.05" to "100,05" wihich results in;

An expression of non-boolean type specified in a context where a condition is expected, near ','.

What is the best way to do this?

A: 

This strikes me as less of a LINQ issue and more of a SubSonic issue. Taking a quick peek at their LINQ parser it looks like constant values are handled with ToString() with no regard for culture (see SubSonic.Linq.Structure.TSqlFormatter.VisitConstant). Writing/contributing a patch for this would be ideal (to either allow specification of a culture or at least to use invariant by default), otherwise I think you're stuck switching the thread culture.

dahlbyk
A: 

Thank you for the answer. As a solution I have modified the SqlServer.ttinclude template to switch to invariant culture in the Find method. Not a perfect but temporary solution, I'll create a patch or at least report the problem to SubSonic.