Current filter:
                                You should refresh the page.
                                0
                                  • Hi,

                                    I have a problem using the following XPQuery (I removed everything not relevant to demonstrate the issue, so don't worry about the purpose of the statement):

                                    int count = new XPQuery<MemberGroup>(session).Where(
                                    c => c.Oid == ag.MemberGroup.Oid
                                    && c.ParentMemberGroup == ag.MemberGroup.ParentMemberGroup).Count();

                                    with ag.MemberGroup.Oid being 3 and ag.MemberGroup.ParentMemberGroup being null.

                                    The result is 0, although according to the database it should be 1. If I change the second criteria to
                                    ((c.ParentMemberGroup == null) || (c.ParentMemberGroup == ag.MemberGroup.ParentMemberGroup))
                                    then it works.

                                    We have an SQL Tracer logging all SQL statements to the DB - this statement is missing in the log, although no error occurs.

                                    So far I thought that XPO handles null values in objects automatically?

                                    Regards
                                    Tom

                                0

                                Hi Tom,

                                I've converted this question into a bug report and passed it to our development team. We'll notify you about our progress on this issue.

                                Thanks,
                                Uriah.

                                Q243239.ZIP
                                0

                                Hi Tom,

                                Sorry, we can't address this problem. When the LINQ expression is processed by XPO, the value of the variable isn't yet recognized and we can't determine whether the variable has a value. So, the query is transformed in the BinaryOperator. The BinaryOperator always returns False, if the OperatorType is BinaryOperator.Equal and the RightOperand is null. This is by design, because different SQL server handle the comparison with null values in a different manner. To resolve this problem, I suggest that you manually check whether the value of the variable is null:

                                	
                                [C#]
                                int count = new XPQuery<MemberGroup>(session).Where( mg => mg.Oid == ag.MemberGroup.Oid && ( ag.MemberGroup.ParentMemberGroup == null ? mg.ParentMemberGroup == null : mg.ParentMemberGroup == ag.MemberGroup.ParentMemberGroup ) ).Count();

                                Thanks,
                                Uriah.

                                You must  log in  or  register  to leave an answer

                                Is your intention to post an answer to your own question?

                                • If so, then proceed.
                                • If you simply wanted to post additional information, ask for further clarification, or to just say "Thanks!", please click Leave a Comment.
                                • If you wish to edit your original question, please use the Edit button in the Toolbox at the top right corner of that entry.