我在玩 Sharp Architecture Lite,它强调约定优于配置,并试图了解 NHibernate是如何ConventionModelMapper
工作的。具体来说,我无法区分下面的 IsRootEntity 和 IsEntity 方法(顺便说一句,Entity
是 Sharp Arch 附带的抽象类):
internal static class Conventions
{
public static void WithConventions(this ConventionModelMapper mapper, Configuration configuration) {
Type baseEntityType = typeof(Entity);
mapper.IsEntity((type, declared) => IsEntity(type));
mapper.IsRootEntity((type, declared) => baseEntityType.Equals(type.BaseType));
public static bool IsEntity(Type type) {
return typeof(Entity).IsAssignableFrom(type)
&& typeof(Entity) != type
&& !type.IsInterface;
}
}
我收集到该IsEntity
方法用于告诉 NHibernate 哪些类有资格映射/持久化到数据库。但是,我一生都无法弄清楚该IsRootEntity
方法的作用。周围的文档ConventionModelMapper
非常稀少。