nhibernate/nhibernate-core — pull request #99 by julian-maughan (2012-05-06 15:40:38+00:00)
Title: Add expression transformer to remove unwanted char-to-int conversions (NH-3124)

As per https://nhibernate.jira.com/browse/NH-3124, the following expression:

```csharp
var user = s.Query().Where(x => x.SomeChar == 'A').ToList();
```
...generates SQL like this:

```sql
select * from [User] where cast(SomeChar as INT)=@p0
Name:p1 - Value:65
```

The cast is invalid and raises an exception. It is also unnecessary, given matching types in the expression. This is not caused by a bug in NHibernate, the IQueryable expression tree actually contains the conversion as if it had been written ".Where(x => (int)x.SomeChar == 65)".

A related discussion can be found here:
http://stackoverflow.com/questions/2072573/lambda-expression-compilation

This pull request attempts to fix the issue by identifying and removing the unwanted conversion.

An alternate solution would be to generate a valid conversion in the SQL statement. For SQL Server, this would be "WHERE UNICODE(x.Type) = 65". This is what LINQ2SQL does. In my view, it is cleaner to remove the conversion altogether, giving:

```sql
select * from [User] where SomeChar=@p0
Name:p1 - Value:'A'
```

I believe this is related to two similar issues that could be fixed in a similar way:

https://nhibernate.jira.com/browse/NH-2812
https://nhibernate.jira.com/browse/NH-2789