locked
Count and Sum based on Screen Parameter RRS feed

  • Question

  • Hi, 

    I have 2 tables: 

    PRODUCER (ID, Name, RECEIVEDOCKETS, )

    RECEIVEDDOCKET (ID, Date, TotalMoney, RECEIVEDDOCKETDETAILS)

    (a Producer can have many RECEIVEDDOCKET instances)

    I wanna count total received dockets and sum total money for each Producer so I add 2 compute field named TotalReceivedDockets, TotalMoney to PRODUCER tbl with the methods below:

                

    partial void TotalReceivedDocket_Compute(ref int? result)
            {            
                    result = this.RECEIVEDDOCKETs.Count();
            }

    partial void TotalMoney_Compute(ref decimal? result)
            {
    result = this.RECEIVEDDOCKETs.Sum(i=> i.TotalMoney);

            }

    In the PRODUCER Search Screen, I created 2 parameter: StartDate and EndDate. I just want 2 compute field'll show the result with Received Dockets having Date in range. I tried many ways but it didn't work.

    Anyone help me plz?

    Saturday, January 19, 2013 8:09 AM

Answers

  • You can't use screen data to calculate computed properties. If you need screen data involved in the calculation, you'll need an ordinary property in your entity.

    Then in the screen's code, by implementing INotifyPropertyChanged if you need to see the result on the screen before the entity is saved, or in the screen's Saving method if you don't.

    Whichever method you choose, you do the calculation in it (with a LINQ query that uses your screen data as parameters), then store the result in the ordinary property.


    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    Please click "Mark as Answer" if a reply answers your question. Please click "Vote as Helpful" , if you find a reply helpful.
     
    By doing this you'll help others to find answers faster.

    • Marked as answer by Little_1991 Thursday, January 24, 2013 4:26 AM
    Monday, January 21, 2013 3:01 AM
    Moderator