Ticket T288428
Visible to All Users

LinqToXpo - Translate nested CASE statements into several WHEN statements when the maximum limit (10) is exceeded

created 9 years ago (modified 9 years ago)

Hello,

I have a L INQ to Sql statement that is run against several joined tables, with one "MajorTable", which has links to all other. Problem is that if in select statement I have nested conditions, they are translated to nested case statements. Since CASE statements are nested I hit a limit of maximum of 10  nested CASE statements. Solution would be to translate it to one CASE statement with several WHEN statements.

Explanation:
Statement looks like:

C#
var myDataJoined = MajorTable .Join(new XPQuery<Table1>(session), link => link.ToId, Table1Rec => Table1Rec.Oid, (link, Table1Rec) => new { Table1Rec = Table1Rec, link = link }) .Join(new XPQuery<Table2>(session), link => link.link.ToId, Table2Rec => Table2Rec.Oid, (link, Table2Rec) => new { Table2Rec = Table2Rec, Table1Rec = link.Table1Rec, link = link.link }) .Join(new XPQuery<Table3>(session), link => link.link.ToId, Table3Rec => Table3Rec.Oid, (link, Table3Rec) => new { Table3Rec = Table3Rec, Table2Rec = link.Table2Rec, Table1Rec = link.Table1Rec, link = link.link }) .Join(new XPQuery<Table4>(session), link => link.link.ToId, Table4Rec => Table4Rec.Oid, (link, Table4Rec) => new { Table4Rec = Table4Rec, Table3Rec = link.Table3Rec, Table2Rec = link.Table2Rec, Table1Rec = link.Table1Rec, link = link.link }); var resultingData = linksJoined.Select(entity => new MyRow() { Oid = entity.Table1Rec != null ? entity.Table1Rec.Oid : (entity.Table2Rec != null ? entity.Table2Rec.Oid : (entity.Table3Rec != null ? entity.Table3Rec.Oid : (entity.Table4Rec != null ? entity.Table4Rec.Oid : (Guid.Empty)))), SomeData = entity.Table1Rec != null ? entity.Table1Rec.Col1 : (entity.Table2Rec != null ? entity.Table2Rec.LastName : (entity.Table3Rec != null ? entity.Table3Rec.SomeCol : (entity.Table4Rec != null ? "FixedText" : ("NO DATA")))), });

This query is translated to SQL which looks like:

C#
select case when not (N1.OID is null) then N1.OID else case when not (N2.OID is null) then N2.OID else case when not (N3.OID is null) then N3.OID else case when not (N4.OID is null) then N4.OID else '00000000-0000-0000-0000-000000000000' end end end end, case when not (N1.OID is null) then N1.Col1 else case when not (N2.OID is null) then N2.LastName else case when not (N3.OID is null) then N3.SomeCol else case when not (N4.OID is null) then N'Fixed text' else N'NO DATA' end end end end ...

Instead it should be translated to:

C#
select case when not (N1.OID is null) then N1.OID when not (N2.OID is null) then N2.OID when not (N3.OID is null) then N3.OID when not (N4.OID is null) then N4.OID else '00000000-0000-0000-0000-000000000000' end, case when not (N1.OID is null) then N1.Col1 when not (N2.OID is null) then N2.LastName when not (N3.OID is null) then N3.SomeCol when not (N4.OID is null) then N'Fixed text' else N'NO DATA' end ...

As it is clear, this statement can run even if there are more when statements.

Thank you.

Show previous comments (7)
Dennis Garavsky (DevExpress) 9 years ago

    Muris,

    Our initial research shows that this task cannot be accomplished in the current version without modifications of the XPO source code and then its further recompilation. At this stage, we do not have complete instructions for accomplishing this customization yet as this requires further research. While allocating our R&D resources at this research right away is not really possible (because that would technically mean implementing this feature bypassing or affecting other release plans), we will try to expedite this particular improvement regarding future updates, though as I said above I cannot give 100% implementation promises at this time. You will automatically be informed of any ticket status changes via email, as always.

    Dennis Garavsky (DevExpress) 9 years ago

      Muris,

      We have made an exception for you and implemented this feature in the next minor update. We hope to hear from you on how this works once the new version is out. Thanks.

        Thank you all guys, especially you Dennis for putting this in next release! You are the best!

        Answers approved by DevExpress Support

        created 9 years ago (modified 9 years ago)

        We have implemented the functionality described in this ticket. It will be included in our next update(s).

        Please check back and leave a comment to this response to let us know whether or not this solution addresses your concerns.

          Show previous comments (2)

            It works as expected!

            Dennis Garavsky (DevExpress) 9 years ago

              Thanks for testing, Muris!

                Thanks for implementing, Dennis! :)

                Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

                Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.