I have an employee object which has a list of EmployeeProject objects. This object indicates which employee is involved in which project. It has an Employee property and a Project property.
The user can select a project in a listbox and add it to another listbox with involved projects. The project is added to the employee like this:
Code:
private void btnAdd_Click(object sender, System.EventArgs e)
{
ListItem item = lbxProjects.SelectedItem;
if (item != null)
{
EmployeeProject proj = new EmployeeProject();
proj.Employee = _employee;
proj.Project= (Project)MyUtils.GetObjectById(typeof(Project), Int32.Parse(item.Value));
_employee.Projects.Add(proj);
lbxEmployeeProjects.Items.Add(item);
item.Selected = false;
}
}
But when I save the employee, the EmployeeProject objects are not saved to the database. I guess my mapping file isn't correct yet for the EmployeeProject collection:
Code:
<bag name="Projects" table="employeeproject" lazy="true">
<key column="employeeid"/>
<one-to-many class="MyApp.Core.Domain.EmployeeProject, MyApp.Core"/>
</bag>
What do I need to do to save the EmployeeProject objects?