This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hello, I've been using the code contained in this post (Dynamically Composing Expression Predicates): http://www.mindscapehq.com/forums/Post.aspx?ThreadID=3232&PostID=10722. I'm trying to build a query with a where clause looking like that: (... and ... and ... and ...) or (... and ... and ... and ...) where ... are conditions using Contains(). The number of conditions are unknown, hence my using of dynamic predicates. Now, the left and right parts are working fine on their own using Contains(), but whenever I try to combine them using the OR clause, it throws this exception: System.InvalidCastException : Unable to cast object of type 'Mindscape.LightSpeed.Querying.IdentifierExpression' to type 'Mindscape.LightSpeed.Querying.LiteralExpression'. For the sake of testing, I replaced my Contains() by Equals() and the exception is not thrown. Obviously, that's not what i want to do here ;) Here is my code, in case it's just bad sequencing of my part: public IEnumerable<Compagnie> GetCompaniesByKeywords(string keywords) Thank you in advance, -Jonathan |
|
|
Could you try this on a current nightly build? Your code works for me so I think this may be something we have already fixed. If it still fails on the latest nightly could you provide us with the stack trace for the exception and ideally a small buildable project (console app or NUnit test) that exhibits the error? Thanks! (As a side note I am not sure the expression actually does what you want because it will result in SQL of the form WHERE ((LegalName = 'kw1' AND LegalName = 'kw2') OR (...[LIKE clauses]...)), the first clause of which will never be true if there is more than one distinct keyword. Perhaps you mean to be OR-ing your expressions in the loop?) |
|
|
Hello, After trying to write a test project to reproduce the bug, I found out that I had miswritten my code and solved my immediate problem. Still, in attachement is a test project containing a test reproducing the bug i stumbled upon. Essentially, it doesn't like a Contains() with a char as argument. Have fun and thanks again! -Jonathan |
|
|
Thanks for drawing our attention to this. We missed this because String.Contains(char) isn't actually the String.Contains method -- it's the IEnumerable<T>.Contains extension method. We were always treating IEnumerable<T>.Contains as being an IN query, but of course that's not right for IEnumerable<char>.Contains! We'll have a fix for this in the next nightly build, or of course you can get around it by passing a single-character string instead of a char. Thanks again for letting us know! |
|