Ticket Q457501
Visible to All Users

Single in PersistentAlias causes freeze when sorting

created 12 years ago
C#
[PersistentAlias("Iif(Invoice.Payments[PaymentDirectionType = 'Inbound'].Count() > 1, 'Multiple', Iif(Invoice.Payments[PaymentDirectionType = 'Inbound'].Count() = 0, '', Invoice.Payments[PaymentDirectionType = 'Inbound'].Single(PaymentType.Name)))")] public string PaymentType { get { return (string)EvaluateAlias("PaymentType"); } }

Sorry there is no sample yet. But basically, I added this property

The logic works great, but when sorting a listview by this property, it hangs and never recovers. Even with a very tiny data set.

Show previous comments (2)

    Only happens in Server Mode, by the way. With Server Mode at false it behaves fine.

      Here is your MainDemo doing it.
      I added a property to Department called "ContactName" which performs the same logic. If there is more than one contact, Contact Name = "Multiple Contacts" -- otherwise it's the single object.
      Run attachment, go to Department ListView. Create a new department with 2 new contacts and save. On the Department Listview, attempt to sort by ContactName.

      DevExpress Support Team 12 years ago

        Thank you for your report. We need some time to research this issue. We will get back to you once we have any results or need extra information. Your patience is appreciated.

        Answers approved by DevExpress Support

        created 12 years ago (modified 12 years ago)

        We have researched this issue and come to the conclusion that the Single aggregate cannot be used in this context. You can use the Single aggregate only if a collection under no circumstances can return more than one row.
        In your example, a server mode grid will execute the following SQL:

        SQL
        select N0."Oid" from (("dbo"."Department" N0 left join "dbo"."Contact" N7 on (N0."Oid" = N7."Department")) left join "dbo"."Person" N8 on (N7."Oid" = N8."Oid")) where N0."GCRecord" is null order by case when ((select count(*) as Res from (("dbo"."Contact" N1 inner join "dbo"."Person" N2 on (N1."Oid" = N2."Oid")) inner join "dbo"."Party" N3 on (N2."Oid" = N3."Oid")) where ((N0."Oid" = N1."Department") and N3."GCRecord" is null)) > 1) then N'Multiple Contacts' else case when not (exists(select * from (("dbo"."Contact" N4 inner join "dbo"."Person" N5 on (N4."Oid" = N5."Oid")) inner join "dbo"."Party" N6 on (N5."Oid" = N6."Oid")) where ((N0."Oid" = N4."Department") and N6."GCRecord" is null))) then null else N8."FirstName" + N8."MiddleName" + N8."LastName" end end asc,N0."Oid" asc

        Because of the left join operator, the result set will contain two rows with the same Oid instead of one. The server mode data source detects this inconsistency and throws an exception.
        Please also refer to ticket Documentation - Improve documentation on the Single aggregate (add examples, describe limitations, etc.).

          Show previous comments (4)
          DevExpress Support Team 12 years ago

            Hi Nate,
            We have researched your second scenario and found that the exception thrown is also by design. When you sort by a reference type property, XAF appends the object's default property to the property path. Since one of the IIF operator branches returns Null, the alias expander cannot create a valid property path with it by appending the display name property and throws an exception.

            J J
            Jacob de Boer © 8 years ago

              Hi Michael

              Can we prevent this exception without changing the alias? We also are using a reference property that uses the Min() function. I asked this in ticket: https://www.devexpress.com/Support/Center/Question/Details/T499113

              The conclusion here is that I can't use a Min() or a Single() function. What can I do to prevent the exceptions?

              Thanks,
              Jacob

              DevExpress Support Team 8 years ago

                @Jacob: Unless I'm mistaken, my colleague already suggested a solution to avoid the exception in your scenario in the T499113 ticket. If it doesn't meet your requirements, please reactivate the original ticket. We will do our best to find a another solution.

                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.