I'm trying to map an Id from an Identity class with Fluent NHibernate.
Identity class:
public interface IValueObject<T> {
bool SameValueAs(T other);
}
[Serializable]
public class Identity<TEntity> : IValueObject<Identity<TEntity>> {
public long Id { get; protected set; }
public Identity(long id) {
this.Id = id;
}
protected Identity() { }
public bool SameValueAs(Identity<TEntity> other) {
return other != null && this.Id == other.Id;
}
}
Model:
public interface IEntity<T> {
Identity<T> Identity { get; }
bool SameIdentityAs(T other);
}
public class Employee: IEntity<Employee> {
public virtual Identity<Employee> Identity { get; set; }
public virtual string Name { get; set; }
}
How can I map this Employee? This way doesn't work, I get the following exception when building the SessionFactory: Could not find a getter for property 'Id' in class 'Employee'
public class EmployeeMap : ClassMap<Employee> {
public EmployeeMap() {
Id(x => x.Identity.Id).GeneratedBy.Native();
Map(x => x.Name);
}
}