【发布时间】:2012-08-16 08:42:12
【问题描述】:
我正在尝试使用 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”的吸气剂
public class EmployeeMap : ClassMap<Employee> {
public EmployeeMap() {
Id(x => x.Identity.Id).GeneratedBy.Native();
Map(x => x.Name);
}
}
【问题讨论】:
标签: c# nhibernate fluent-nhibernate fluent-nhibernate-mapping