locked
LightSwitch Computed Property: Unresolved Error RRS feed

  • Question

  • I have a Project table as shown below:

    Project

    Id (Integer)
    Title (String)
    Status (String)

    I want to add a computed property called Count which counts the number of projects with the status "Open".
    The requirement is that if there is already a project open then I can not add another entry in this table with Status = "Open".

    I created a simple query (Query1) to filter such that only Status = "Open" are kept.

    Then to count the records, I wrote the following code:

     public partial class Project
        {
            partial void Count_Compute(ref int result)
            {
                // Set result to the desired field value
                result = this.DataWorkspace.ApplicationData.Query1.Execute().Count; 
            }
        }

    Which gives me the error: "C#: Unknown member 'DataWorkspace' of 'LightSwitchApplication.Project'.

    Can anyone please help me with the issue?




    • Edited by rpv04 Tuesday, June 17, 2014 8:57 PM
    Tuesday, June 17, 2014 6:45 PM

Answers

  • DataWorkspace is a property of the Application object, not your Project object (this).

    Simon Jones
    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, please remember to "Mark as Answer". This will help other people find answers to their problems more quickly.

    • Proposed as answer by Simon Jones [MSDL] Saturday, June 21, 2014 9:51 AM
    • Marked as answer by Angie Xu Wednesday, June 25, 2014 7:15 AM
    Tuesday, June 17, 2014 9:45 PM
  • Made some changes to the code.

    And it worked!

    partial void Count_Compute(ref int result)
            {
               var filteredRecords = DataWorkspace.ApplicationData.Query1();
                result = filteredRecords.Count();
            }
    
            


    • Edited by rpv04 Monday, June 23, 2014 12:17 PM
    • Marked as answer by Angie Xu Wednesday, June 25, 2014 7:15 AM
    Monday, June 23, 2014 12:16 PM

All replies

  • DataWorkspace is a property of the Application object, not your Project object (this).

    Simon Jones
    If you found this post helpful, please "Vote as Helpful". If it actually answered your question, please remember to "Mark as Answer". This will help other people find answers to their problems more quickly.

    • Proposed as answer by Simon Jones [MSDL] Saturday, June 21, 2014 9:51 AM
    • Marked as answer by Angie Xu Wednesday, June 25, 2014 7:15 AM
    Tuesday, June 17, 2014 9:45 PM
  • Made some changes to the code.

    And it worked!

    partial void Count_Compute(ref int result)
            {
               var filteredRecords = DataWorkspace.ApplicationData.Query1();
                result = filteredRecords.Count();
            }
    
            


    • Edited by rpv04 Monday, June 23, 2014 12:17 PM
    • Marked as answer by Angie Xu Wednesday, June 25, 2014 7:15 AM
    Monday, June 23, 2014 12:16 PM