locked
I'd like to update a table in AdventureWorks Database without Datagrid and DataForm. RRS feed

  • Question

  • I am tring http://msdn.microsoft.com/ja-jp/library/ff713719(v=vs.91).aspx

    In my Solution DataGrid or DataForm is not nessesary. So I deleted them and modified cs or xaml files. Fortunately I succesed Query and Insert to the table "Employee". But I can not Update. These code is ...

            private void UpdateButton_Click(object sender, RoutedEventArgs e)
            {
                UpdateButton.IsEnabled = false;
                OrganizationContext MyC = (OrganizationContext)(employeeDataSource.DomainContext);
                foreach (Employee emp in MyC.Employees) {
                    emp.Gender="G";                                           // Can I set the value directory ? I don't know.
                    MyC.UpdateEmployee(emp);
                }
                UpdateButton.IsEnabled = false;
                employeeDataSource.SubmitChanges();
                UpdateButton.Content = "OK";
            }

            private void employeeDataSource_SubmittedChanges(object sender, SubmittedChangesEventArgs e)
            {
                if (e.HasError)
                {
                    MessageBox.Show(string.Format("Changes were not saved: {0}", e.Error.Message));
                    e.MarkErrorAsHandled();
                }
                UpdateButton.IsEnabled = true;

            }

    Error is ...System.NotSupportedException was unhandled by user code
      Message=This EntitySet of type 'HRApp.Web.Employee' does not support the 'Edit' operation.
      StackTrace:
           at System.ServiceModel.DomainServices.Client.EntitySet.EnsureEditable(EntitySetOperations operation)
           at System.ServiceModel.DomainServices.Client.Entity.RaiseDataMemberChanging(String propertyName)
           at HRApp.Web.Employee.set_Gender(String value)
           at HRApp.Views.EmployeeList.UpdateButton_Click(Object sender, RoutedEventArgs e)
           at System.Windows.Controls.Primitives.ButtonBase.OnClick()
           at System.Windows.Controls.Button.OnClick()
           at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
           at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
           at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)
      InnerException:

     

     

    Saturday, August 14, 2010 9:00 PM

Answers

All replies

  • I found the error happend just this step.

    emp.Gender="F";   // Sorry but I changed the letter.                                

    Why does the property Gender reject the value ? Or let me know the way to set the value to emp.Gender.  Details are bellow. this.RaiseDataMemberChanging("Gender") rejects that the value changes.

    [DataMember()]
            [Required()]
            [RoundtripOriginal()]
            [StringLength(1)]
            public string Gender
            {
                get
                {
                    return this._gender;
                }
                set
                {
                    if ((this._gender != value))
                    {
                        this.OnGenderChanging(value);
                        this.RaiseDataMemberChanging("Gender");
                        this.ValidateProperty("Gender", value);
                        this._gender = value;
                        this.RaiseDataMemberChanged("Gender");
                        this.OnGenderChanged();
                    }
                }
            }

    Sunday, August 15, 2010 12:14 AM
  • bs6,

     This is the wrong forum for this question.

     Please visit the RIA Services forum for any help with this issue:

    http://forums.silverlight.net/forums/53.aspx


    Phani Raj Astoria http://blogs.msdn.com/PhaniRaj
    Monday, August 16, 2010 4:12 AM
    Moderator