我正在尝试使用 Fluent NHibernate 从 Identity 类映射 Id。
身份等级:
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;
}
}
模型:
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; }
}
如何映射此员工?这种方式不起作用,在构建 SessionFactory 时出现以下异常:在“Employee”类中找不到属性“Id”的 getter
public class EmployeeMap : ClassMap<Employee> {
public EmployeeMap() {
Id(x => x.Identity.Id).GeneratedBy.Native();
Map(x => x.Name);
}
}