I got stuck trying to implement CompositeId.
I'm using the NHibernate AttributeMapper.
my data structure:
1) User-Table with id and several other fields
2) UserSetting Table where the UserId, a setting name and a value are stored. the userName and the setting should be the key together. also the UserId should be mapped to a User-Instance.
heres the code:
User:
Code:
[NHibernate.Mapping.Attributes.Class(Table="_tblBenutzer")]
public class User
{
[NHibernate.Mapping.Attributes.Id(0,Column="id",TypeType=typeof(int),UnsavedValue="0")]
[NHibernate.Mapping.Attributes.Generator(1, Class = "native")]
[NHibernate.Mapping.Attributes.CompositeElement(3,ClassType = typeof(User))]
public virtual int Id { get { return _id; } set { _id = value; } }
[NHibernate.Mapping.Attributes.Property(Column = "benutzername", NotNull = false, TypeType = typeof(string), Length = 50)]
public virtual string Benutzername { get { return _username; } set { _username = value; } }
..... and so on..
UserSetting:
Code:
[NHibernate.Mapping.Attributes.Class(Table = "tblBenutzerKonfiguration")]
public class UserSetting
{
[NHibernate.Mapping.Attributes.CompositeId(0)]
[NHibernate.Mapping.Attributes.KeyProperty(1, Name = "Name", Column = "name", TypeType=typeof(string))]
[NHibernate.Mapping.Attributes.KeyManyToOne(2, Name = "User", Column = "benutzerId", ClassType=typeof(User))]
public virtual User User { get { return _user; } set { _user = value; } }
public virtual string Name { get { return _name; } set { _name = value; } }
[NHibernate.Mapping.Attributes.Property(0, Column = "wert", NotNull = false, TypeType = typeof(string), Length = 1000)]
public virtual string Value { get { return _value; } set { _value = value; } }
....
thats it.. but when i try to run my project i get an error at:
Code:
config.AddInputStream(NHibernate.Mapping.Attributes.HbmSerializer.Default.Serialize(
System.Reflection.Assembly.GetExecutingAssembly()));
saying: "Could not compile deserialized mapping document."
what am i doing wrong?