开发者

Fluent NHibernate - Map only a few classes in assembly

I have a entity project which holds about 30 classes and this project is used in several web applications. One application maybe uses all the 30 classes but another one only uses 3 classes. So my question is: How can I add just the classes that a uniqe application needs? My first thought was to add the names of the needed classes in app settings in web.config like:

<add key="Mapping开发者_如何学JAVAClasses" value="User,Application,News" />

And then split and loop in the configuration of the session factory. But I really would like your input on this! What is the best approach to achieve this?


You can tell to your AutoPersistenceModelGenerator to Filter classes by some criteria.

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<>));
    }

So now you could read your config file and using reflection to create your filter criteria.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜