Ticket Q302237
Visible to All Users
Duplicate

SUM Detail Master

created 14 years ago

Please help and suggest best practice for follow scenario
Customer
      Document
          DocumentLines
Item
Customer has Association to Document
Document has Association to DocumentLines
Item has Association to DocumentLines
How to calculate Totals on Customer, Document and Item
Image that there are about 200 Customers, 50 Items, every customer has daily (200 to 250 days per year) one Document (invoice or deliverynote or cancelationnote) every document has from 5 to 10 DocumentLines and we want document history for 5 year. It means we will have about 2.000.000 to 2.500.000 DocumentLines.

Show previous comments (5)
DevExpress Support Team 14 years ago

    Hi Panagiotis,
    A new DocumentLine object is created when any cell value is set in the grid's new item row. When you set the Item property, it should update its associated collection of DocumentLines. To add a newly created DocumentLine to it, XPO has to load all objects in this collection (see suggestion XPO should not automatically pre-load an associated collection when I only need to insert a new object into it). What is worse, all associated Document objects are also loaded, because the DocumentLine object has a reference to Document. Retrieving Documents generates a lot of queries, because they are retrieved by their keys. You can avoid automatic loading of Document objects by enabling delayed loading for the DocumentLine.Document property. Please refer to the Delayed Loading help topic.
    As for database indices, XPO does not automatically create them, because it is impossible to determine when they are necessary. This optimization should be done based on real life scenarios and tests. You can use the Indexed attribute to instruct XPO to create a database index.
    Thanks,
    Michael.

    PB PB
    Panagiotis Bourelias 14 years ago

      Thank you for your answer.
      Please suggest how to calculate Item.DocumentLinesTotal (QuantityDebit, QuantityDebit …) if I will remove Association (<Association("Item-DocumentLine")>) from class Item
      Take in account that in the class Item there are more properties that should be calculated online so the LookupEditors will have correct balances
      Public Class Item
           Inherits XPBaseObject
           Public Sub New(ByVal session As Session)
                MyBase.New(session)
           End Sub
           Public Overrides Sub AfterConstruction()
                MyBase.AfterConstruction()
           End Sub
           <Key(True)>
           Public Property Oid() As Integer
           Public Property Description() As String
           'Uncomented Line
           '<Association("Item-DocumentLine")>
           Public ReadOnly Property DocumentLines() As XPCollection(Of DocumentLine)
                Get
                     Return GetCollection(Of DocumentLine)("DocumentLines")
                End Get
           End Property
           Public Property DocumentLinesTotal() As Nullable(Of Decimal)
           Public Property QuantityDebit() As Nullable(Of Decimal)
           Public Property QuantityCredit() As Nullable(Of Decimal)
           Public Property AmountDebit() As Nullable(Of Decimal)
           Public Property AmountCredit() As Nullable(Of Decimal)
           Public Overrides Function ToString() As String
                Return Me.Description
           End Function
      End Class
      Thanks
      Panos

      DevExpress Support Team 14 years ago

        Hi Panos,
        If you want to remove the association, you should rewrite your DocumentLinesTotal property to use an explicitly created collection, filtered to contain related objects.

        Visual Basic
        Dim total As Decimal = 0 Dim documentLines As New XPCollection(Of DocumentLine)(Session, New BinaryOperator("Item", This)) For Each c As DocumentLine In documentLines total += c.Amount Next c m_documentLinesTotal = total

        I'm looking forward to hearing from you.
        Thanks,
        Michael.

        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.