I'd like to map following classes, but I'm not able to figure out how to
define the mappings (I'm using mapping by code):
public class Employee : EntityBase
{
public virtual string FirstName { get; protected set; }
public virtual string LastName { get; protected set; }
public virtual string EmpNumber { get; protected set; }
public virtual IDictionary<Month, Salary> Salaries { get; protected set; }
}
public class Salary
{
public virtual Month Month { get; protected set; }
public virtual decimal Amount { get; set; }
}
public class Month
{
public virtual int Year { get; protected set; }
public virtual int MonthNumber { get; protected set; }
}
The problem is I can't get Salary.Month mapped, because Month is also the
key of Employee.Salaries dictionary. If I try to map the Month using
following mapping code I get NHibernate.MappingException : Repeated column
in mapping for collection: Employee.Salaries column: Year.
mapper.Class<Employee>(ca =>
{
ca.Id(x => x.Id);
ca.Property(x => x.FirstName, m => m.UniqueNotNull());
ca.Property(x => x.LastName, m => m.NotNullable(true));
ca.Property(x => x.EmpNumber, m => m.NotNullable(true));
ca.ManyToOne(x => x.User, m => m.NotNullable(true));
ca.Map(x => x.Salaries,
m =>
{
m.Key(x => x.Column("EMPLOYEE_ID"));
m.Table("EMPSALARIES");
},
m => m.Component(c =>
{
c.Property(x => x.Year);
c.Property(x => x.MonthNumber);
}),
m => m.Component(c =>
{
c.Property(x => x.Amount);
c.Component(x => x.Month,
x =>
{
x.Property(xx => xx.Year);
x.Property(xx =>
xx.MonthNumber);
});
}));
});
I was also trying to map the month as a component explicitely using
mapper.Component() and than mapping Sallaries without specifying any key and
element mapping, but result was just the same. Is there any trick how to
achieve this?
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/nhusers/-/5vSpbqUbxQMJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.