I am experiencing this exception when trying to define a data member contained within another piece of data.
Example:
Container newRecord = this.DataWorkspace.ApplicationData.Containers.AddNew();
newRecord.SubContainer = this.DataWorkspace.ApplicationData.SubContainers.AddNew();
The exception, "Reference properties cannot be set to deleted or discarded entities.", is encountered with the second line.
I don’t understand what entity it’s talking about with regard to it being discarded or deleted, so any help with this issue would be most appreciated.
The code lines are in an interface function defined in LightSwitch, which is called from a Silverlight project, passing data from that project to the LightSwitch project.
I eventually managed to do this after working out that I needed to be on the ‘Logic’ thread, which I was not. I spent a little while messing around trying to find a
this.DataContextbut could not (my Silverlight project had this but not the LightSwitch project).Eventually though I found out what I needed to do:
I can then assign data to the properties of
newRecordand the properties of the objects it contains (such as the exampleSubContainer‘s properties), although obviously the new record is not saved until LightSwitch is instructed to save its data.