1

I'm trying to implement the following code into a LightSwitch 2012 project. I'm getting an error when I try to assign the this.ExpenseReport to a value. The error reads "Property or indexer 'LightSwitchApplication.ExpenseReportDetails.ExpenseReport' cannot be assigned to -- it is read only".

partial void ExpenseReportDetails_InitializeDataWorkspace(List<IDataService> saveChangesTo)
    {

        // Write your code here.
        if (this.ExpenseReportId == -1) // -1 means new Report    
        {        // Create a new ExpenseReport        
            this.ExpenseReport = new ExpenseReport();
        }
        else
        {
            // Get existing Expense Report        
            this.ExpenseReport = this.DataWorkspace.ApplicationData.ExpenseReports_SingleOrDefault(this.ExpenseReportId);

            // Set the name of the Tab to the default field on the Entity        
            this.SetDisplayNameFromEntity(this.ExpenseReport);
        }
Oliver Weichhold
  • 10,259
  • 5
  • 45
  • 87

1 Answers1

0

The implementation of ExpenseReport does not have a set property, only a get propery. THis means that you can not run the following line:

this.ExpenseReport = this.DataWorkspace.ApplicationData.ExpenseReports_SingleOrDefault(this.ExpenseReportId);

Can you change ExpenseReport to be writable?

Guvante
  • 18,775
  • 1
  • 33
  • 64
  • I'm not seeing one. I'm using this code so that when a user selects a record the info will be used to open an ExpenseReportDetails screen. – user2296336 Apr 18 '13 at 18:38