Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Collection was of a fixed size" Exception in EF4 with POCO

I am using EF4 with WCF and POCO. I removed all virtual keyword in POCO entities.

I have Employee and Team entities and relationship between both is 1:N, means that one employee can be allocated only one team.

And I'd like to add new employee with existing team. Following code is in the client side.

private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            Team teamFromDb = ServiceProxy.GetService.GetTeamById(181);
            Employee newEmp = new Employee{ UserName="username"};
            newEmp.Team = teamFromDb;
            ServiceProxy.GetService.AddEmployee(newEmp);                
        }

Following code is in the server side (Dao layer)

public void AddEmployee(Employee emp)
        {
            ctx.Employees.AddObject(emp);
        }

        public Team GetTeamById(int teamId)
        {
            return ctx.Teams.Where(t => t.TeamId == teamId).FirstOrDefault();
        }

Problem is that I got "Collection was of a fixed size" Exception when I add teamFromDb instance to the newEmp.Team property in the client code.

Do I need to add some more code to fix?

In addition, What do I need to for Insert/Update/Delete job with POCO classes and WCF

Thanks in advance.

like image 644
Ray Avatar asked Oct 18 '10 07:10

Ray


1 Answers

Did you tried to replace ICollection to FixupCollection for generated proxy entities(classes)? That may help if you are using WCF with entity framework POCOs

like image 181
dotnetninja Avatar answered Sep 18 '22 16:09

dotnetninja