Unexpected behavior (I think)

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
Hylndr
Posts: 3
Joined: Thu 06 Oct 2016 15:26

Unexpected behavior (I think)

Post by Hylndr » 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:

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;
                }
            }
        }
Here's the viewmodels constructor:

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;
        }
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

Pinturiccio
Devart Team
Posts: 2192
Joined: Wed 02 Nov 2011 09:44

Re: Unexpected behavior (I think)

Post by Pinturiccio » Wed 18 Jan 2017 13:07

Please create and send us a test project with the model for reproducing the issue.

Hylndr
Posts: 3
Joined: Thu 06 Oct 2016 15:26

Re: Unexpected behavior (I think)

Post by Hylndr » Tue 24 Jan 2017 18:39

Just sent in a request that included two projects for testing... Hopefully, we (I mean you guys :-) ) can figure this out, it's really stumping me and is a major roadblock to finishing up a project...

Thanks in advance,

Kevin Orcutt

Shalex
Site Admin
Posts: 8247
Joined: Thu 14 Aug 2008 12:44

Re: Unexpected behavior (I think)

Post by Shalex » Fri 27 Jan 2017 13:08

We have asked for the additional information by email.

Post Reply