nhibernate-core
nhibernate-core copied to clipboard
NH-3225 - Linq: Add support for bitwise And, Or operators
rosieks created an issue — :
When I create linq query that use AND operator (&) like below i get InvalidCastException:
session.Query<Person>().Where(p => p.Name.Contains("Jo") & p.Address.Contains("War")).ToArray();
My current workaround is to use AndAlso operator (&&).
The issue can be related to NH-2539, because exception is throwed in the same place in AsBooleanExpression method.
rosieks added a comment — :
Test case
Alexander Zaytsev added a comment — :
What is the reasont to use & operator?
rosieks added a comment — :
In my case there was no reason. I just have Filter extension method that dynamically build expression for Where method and it use Expression.And method instead of Expression.AndAlso - that method works great with Entity Framework, but when I use it with NHibernate it doesn't work so I changed it.
Alexander Zaytsev added a comment — :
~PR is ready for review: https://github.com/nhibernate/nhibernate-core/pull/516~ The changes for this issue has been removed from the PR
@hazzik It appears I'm suffering from this same issue and unfortunately I can't change the code that is producing it. I'm using a 3rd party controls software called SyncFusion and they have a dynamic linq generator that translates query criteria being sent from a vue based javascript grid and they are using the Expression.And to join multiple conditionals in the where clause.