Hi,
Im having a problem when I edit an object that has an IList.
Here are the codes for reference:
Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<!--Build: with Personal Nhibernate template-->
<class name="Fleury.Core.Domain.TblCommitteexUser,Fleury.Core" table="TblCommittee_x_User" lazy="true">
<id name="CommitteeUserId" column="CommitteeUserId" type="int">
<generator class="sequence">
<param name="sequence">TBLCOMMITTEE_X_USER_COMMITTEEU</param>
</generator>
</id>
<many-to-one name="TblCommittee" column="CommitteeId" cascade="save-update" not-null="true" />
<many-to-one name="TblUser" column="UserId" cascade="none" not-null="true" />
<property name="DateCreated" column="DateCreated" type="DateTime" />
<property name="CommitteeOrder" column="CommitteeOrder" type="int" not-null="true" />
<property name="Status" column="Status" type="Boolean" />
<property name="Leader" column="Leader" type="Boolean" />
</class>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<!--Build: with Personal Nhibernate template-->
<class name="Fleury.Core.Domain.TblCommittee,Fleury.Core" table="TblCommittee" lazy="true">
<id name="CommitteeId" column="CommitteeId" type="int">
<generator class="sequence">
<param name="sequence">TBLCOMMITTEE_COMMITTEEID_SEQ</param>
</generator>
</id>
<property name="Title" column="Title" type="string" />
<property name="Description" column="Description" type="string" />
<property name="CreationDate" column="CreationDate" type="DateTime" />
<property name="IsActive" column="IsActive" type="Boolean" />
<bag name="TblCommitteeXUser" inverse="true" lazy="true" cascade="all-delete-orphan">
<key column="CommitteeId" />
<one-to-many class="Fleury.Core.Domain.TblCommitteexUser,Fleury.Core" />
</bag>
<bag name="TblEvent" inverse="true" lazy="true" cascade="none">
<key column="CommitteeId" />
<one-to-many class="Fleury.Core.Domain.TblEvent,Fleury.Core" />
</bag>
</class>
</hibernate-mapping>
Code:
int count = 1;
if (oTblCommittee == null)
oTblCommittee = new TblCommittee();
oTblCommittee.Title = txtTitulo.Text;
oTblCommittee.IsActive = (rbtnAtivo.SelectedValue == "1") ? true : false;
oTblCommittee.CreationDate = DateTime.Now;
oTblCommittee.TblCommitteeXUser = new List<TblCommitteexUser>();
foreach (ListItem oListItem in lstAvaliadores.Items)
{
TblCommitteexUser oTblCommitteexUser = new TblCommitteexUser();
oTblCommitteexUser.TblUser = new TblUser();
oTblCommitteexUser.TblUser.UserId = Convert.ToInt32(oListItem.Value);
oTblCommitteexUser.DateCreated = DateTime.Now;
oTblCommitteexUser.TblCommittee = oTblCommittee;
oTblCommitteexUser.CommitteeOrder = count;
oTblCommittee.TblCommitteeXUser.Add(oTblCommitteexUser);
count++;
}
Then I try to edit an existing committee, changing or deleting the Users in the Committee.
After the last piece of code, i call "saveorupdate" passing as parameter the "oTblCommittee".
It inserts the new items in the TblCommitteexUser, updates the title and creationdate, but doesn't delete the old TblCommitteexUsers.
What am I doing wrong?