【问题标题】:Fluent NHibernate - Map only a few classes in assemblyFluent NHibernate - 在程序集中只映射几个类
【发布时间】:2011-02-09 20:05:23
【问题描述】:

我有一个包含大约 30 个类的实体项目,该项目用于多个 Web 应用程序。一个应用程序可能使用所有 30 个类,但另一个应用程序只使用 3 个类。 所以我的问题是: 如何仅添加 uniqe 应用程序所需的类? 我的第一个想法是在 web.config 的应用设置中添加所需类的名称,例如:

<add key="MappingClasses" value="User,Application,News" />

然后在会话工厂的配置中进行拆分和循环。 但我真的很想听听你的意见! 实现这一目标的最佳方法是什么?

【问题讨论】:

    标签: configuration fluent-nhibernate mapping


    【解决方案1】:

    您可以告诉您的 AutoPersistenceModelGenerator 按某些标准过滤类。

    e.q.

        /// <summary>
        /// Provides a filter for only including types which inherit from the IEntityWithTypedId interface.
        /// </summary>
        private bool GetAutoMappingFilter(Type t)
        {
            return t.GetInterfaces().Any(x =>
                                         x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IEntityWithTypedId<>));
        }
    

    所以现在您可以读取配置文件并使用反射来创建过滤条件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-21
      • 2011-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-18
      • 2010-12-09
      • 1970-01-01
      相关资源
      最近更新 更多