I'm absolutely beginner to develop silverlight with RIA
i found the WCF RIA Services sample from silverlight.net by following the tutorial
i get an error while i trying to add new employee
it will pop up one window with message VS JIT Debugger
Code: 4004
Category: Managed Runtime Error
Message: System.ServiceModel.DomainServices.Client.DomainException: An error occurred while submitting changes on the Domain Context of type
I'm using silverlight 4 with AdventureWork2008Entities do this tutorial, and below are the code in the apps
<dataForm:DataForm x:Name="addEmployeeDataForm" AutoGenerateFields="False" AutoCommit="True" AutoEdit="True" CommandButtonsVisibility="None">
<dataForm:DataForm.EditTemplate>
<DataTemplate>
<StackPanel>
<dataForm:DataField Label="Business Entity ID">
<TextBox Text="{Binding BusinessEntityID, Mode=TwoWay}" />
</dataForm:DataField>
<dataForm:DataField Label="Login ID">
<TextBox Text="{Binding LoginID, Mode=TwoWay}" />
</dataForm:DataField>
<dataForm:DataField Label="National ID">
<TextBox Text="{Binding NationalIDNumber, Mode=TwoWay}" />
</dataForm:DataField>
<dataForm:DataField Label="Title">
<TextBox Text="{Binding JobTitle, Mode=TwoWay}" />
</dataForm:DataField>
<dataForm:DataField Label="Marital Status">
<TextBox Text="{Binding MaritalStatus, Mode=TwoWay}" />
</dataForm:DataField>
<dataForm:DataField Label="Gender">
<TextBox Text="{Binding Gender, Mode=TwoWay,NotifyOnValidationError=True, ValidatesOnExceptions=True }" />
</dataForm:DataField>
<dataForm:DataField Label="Salaried">
<CheckBox IsChecked="{Binding SalariedFlag, Mode=TwoWay,NotifyOnValidationError=True, ValidatesOnExceptions=True }" />
</dataForm:DataField>
<dataForm:DataField Label="Active">
<CheckBox IsChecked="{Binding CurrentFlag, Mode=TwoWay,NotifyOnValidationError=True, ValidatesOnExceptions=True }" />
</dataForm:DataField>
</StackPanel>
</DataTemplate>
</dataForm:DataForm.EditTemplate>
</dataForm:DataForm>
Employee Registration Window.xaml
private void addNewEmployee_Click(object sender, RoutedEventArgs e) { EmployeeRegistrationWindow addEmp = new EmployeeRegistrationWindow(); addEmp.Closed += new EventHandler(addEmp_Closed); addEmp.Show(); }
private void addEmp_Closed(object sender, EventArgs e)
{
EmployeeRegistrationWindow emp = (EmployeeRegistrationWindow) sender;
if (emp.NewEmployee != null)
{
OrganizationContext _organizationContext = (OrganizationContext) (employeeDataSource2.DomainContext);
_organizationContext.Employees.Add(emp.NewEmployee);
employeeDataSource2.SubmitChanges();
}
}
Employee List.xaml.cs
public void InsertEmployee(Employee employee)
{
employee.HireDate = DateTime.Now;
employee.ModifiedDate = DateTime.Now;
employee.VacationHours = 100;
employee.SickLeaveHours = 0;
employee.rowguid = Guid.NewGuid();
employee.BirthDate = new DateTime(1967, 3, 18);
if ((employee.EntityState != EntityState.Detached))
{
this.ObjectContext.ObjectStateManager.ChangeObjectState(employee, EntityState.Added);
}
else
{
this.ObjectContext.Employees.AddObject(employee);
}
}
OrganizationService