Hello.
If two classes "DbUser" (parent class) and "DbUserData" (child class) with an one-to-one mapping.
In my example (that works) the UserId where given by DbUserData but thats not what i want. I want that the UserId is given by DbUser because it is the parent class and DbUser must also give die Id to other classes like DbUserData. I hope it's understandable.
the code of DbUser is:
Code:
public class DbUser
{
private int _idUser;
private DbUserData _dbUserData;
public DbUser()
{
_idUser = 0;
_dbUserData = new DbUserData();
_dbUserData.User = this;
}
public int IdUser
{
get { return _idUser; }
}
public DbUserData DbUserData
{
get { return _dbUserData; }
set { _dbUserData = value; }
}
}
and the mapping file looks like this:
Code:
<class name="DbUser" table="DbUser">
<id name="IdUser" column="IdUser" access="field.camelcase-underscore" type="Int32">
<generator class="foreign">
<param name="property">DbUserData</param>
</generator>
</id>
<one-to-one name="DbUserData" class="DbUserData" />
</class>
the code of DbUserData:
Code:
public class DbUserData
{
private int _userId;
private string _name;
private string _password;
private DbUser _user;
public DbUser User
{
get { return _user; }
set { _user = value; }
}
public int UserId
{
get { return _userId; }
set { _userId = value; }
}
public string Name
{
get { return _name; }
set { _name = value; }
}
public string Password
{
get { return _password; }
set { _password = value; }
}
public DbUserData()
{
_name = "";
_password = "";
}
}
and the mapping file:
Code:
<class name="DbUserData" table="DbUserData">
<id name="UserId" column="UserId" unsaved-value="0" access="field.camelcase-underscore" type="Int32">
<generator class="identity"/>
</id>
<property name="Name" access="field.camelcase-underscore" column="Name" type="AnsiString" not-null="true"/>
<property name="Password" access="field.camelcase-underscore" column="Password" type="AnsiString" not-null="true"/>
<one-to-one name="User" class="DbUser" />
</class>
When i try to change the generator tags to:
DbUser:
Code:
<id name="IdUser" column="IdUser" unsaved-value="0" access="field.camelcase-underscore" type="Int32">
<generator class="identity"/>
</id>
DbUserData:
Code:
<id name="UserId" column="UserId" access="field.camelcase-underscore" type="Int32">
<generator class="foreign">
<param name="property">User</param>
</generator>
</id>
then the data of DbUserData will not be saved.
Can anyone say me why?
PS: Please excuses my english :)
regards
Kesch