Unexpected behavior (I think)
Posted: Tue 17 Jan 2017 14:02
Hello All,
I have built a DAL dll using EF6, Devart dotConnect 9.1.131 .Net Framework 4.5.2 and am using it in a WPF application that's pretty simple. The DAL has four table in it: Employee, Department, PlantDtl, and TimeSubmitType... The WPF application main purpose is to add a new employee when hired... In the viewmodel's constructor, it reads a list of departments and displays them in a combobox(in the view...). The app has all the other pertinent details of the employee on it as well... At the bottom is a submit button. In it's command method I call one other method that tries to add the new employee to the dbcontext and save changes... I get an dbUpdateException when I do. I've used the dbmonitor app and it looks like the app is trying to insert back into the department table??? I didn't change anything there, so why is it trying to insert into THAT table??? Here's the code where I'm getting the error:
Here's the viewmodels constructor:
I put the catches in there just to try and see more detail as to what was going on, then I found out about the dbmonitor app.. That help quite a bit in narrowing down what was going on, but still I don't understand why the dbcontext thinks it needs to insert into the department table. For testing purposes I'm giving the new employee say department "D" and for whatever reason the captured SQL from dbmonitor says it's trying to insert department "A". Both of these departments are already in the table. I'm not adding a new department in the code only a new employee... I'm slightly confused here. Big caveat, it's my first time using this particular ORM tool, I've used others before, but not his one.
Thanks in advance,
Kevin Orcutt
I have built a DAL dll using EF6, Devart dotConnect 9.1.131 .Net Framework 4.5.2 and am using it in a WPF application that's pretty simple. The DAL has four table in it: Employee, Department, PlantDtl, and TimeSubmitType... The WPF application main purpose is to add a new employee when hired... In the viewmodel's constructor, it reads a list of departments and displays them in a combobox(in the view...). The app has all the other pertinent details of the employee on it as well... At the bottom is a submit button. In it's command method I call one other method that tries to add the new employee to the dbcontext and save changes... I get an dbUpdateException when I do. I've used the dbmonitor app and it looks like the app is trying to insert back into the department table??? I didn't change anything there, so why is it trying to insert into THAT table??? Here's the code where I'm getting the error:
Code: Select all
private void AddEmployee()
{
using (var dc = new MTDAL.MTDALEntities())
{
dc.Employees.Add(NewEmployee);
try
{
_myMonitor.IsActive = true;
dc.SaveChanges();
}
catch(DbUpdateException ex)
{
throw;
}
}
}
Code: Select all
public MainViewModel()
{
_myMonitor = new OracleMonitor();
using (var dc = new MTDAL.MTDALEntities())
{
TimeSubmitTypes = new ObservableCollection<TimeSubmitType>(dc.TimeSubmitTypes);
DepartmentList = new ObservableCollection<Department>(dc.Departments.Ordered());
SupervisorList = new ObservableCollection<Employee>(dc.Employees.FindAllSupervisors());
NewEmployee = new Employee();
}
RoundingVisible = false;
SelectedVoucherIndex = -1;
SelectedDeptIndex = -1;
SelectedShiftIndex = -1;
SelectedTimeClockIndex = -1;
}
Thanks in advance,
Kevin Orcutt