自定义 Fluent NHibernate 地图无法与 AutoMapping 一起使用

发布于 2024-12-10 21:52:25 字数 1608 浏览 0 评论 0原文

我在使用 Fluent NHibernate AutoPersistenceModelGenerator 时遇到问题。它不想选择自定义地图。

使用 Sharp Architecture 2.0、Fluent NHibernate 1.2 和 NHibernate 3.1。

我当前的相关配置如下:

    public AutoPersistenceModel Generate()
    {
        // This mappings group works with the exception of custom maps!!
        var mappings = AutoMap.AssemblyOf<SecurableEntity>(new AutomappingConfiguration());
        mappings.Conventions.Setup(GetConventions());
        mappings.IgnoreBase<Entity>();
        mappings.IgnoreBase<SecurableEntity>();
        mappings.IgnoreBase(typeof(EntityWithTypedId<>));
        mappings.UseOverridesFromAssemblyOf<AutoPersistenceModelGenerator>();

        //mappings.UseOverridesFromAssemblyOf<UserMap>(); // Should call Override method of UserMap, but doesn't appear to...
        mappings.Override<User>(new UserMap().Override()); // This hack fixes the issue with calling the Override method of UserMap.
        mappings.UseOverridesFromAssemblyOf<UserMap>();

        return mappings;
    }

class UserMap : IAutoMappingOverride<User>
{
    public void Override(AutoMapping<User> mapping)
    {
        //mapping => mapping.Table("Users");
        mapping.Table("Users");
    }

    public Action<AutoMapping<User>> Override()
    {
        return map =>
            {
                map.Table("Users");
            };
    }
}

我尝试对配置进行各种修改并翻遍了Fluent NHibernate的互联网文章,但无济于事。我有一个使用 Sharp Arch 1.x 的工作版本,以及早期版本的 NHibernate 和 Fluent。我假设我所缺少的语法发生了变化。任何和所有的帮助将不胜感激。

谢谢你! 约翰

I'm having an issue with Fluent NHibernate AutoPersistenceModelGenerator. It doesn't want to pick up custom maps.

Using Sharp Architecture 2.0, Fluent NHibernate 1.2 and NHibernate 3.1.

My current relevant configuration is as follows:

    public AutoPersistenceModel Generate()
    {
        // This mappings group works with the exception of custom maps!!
        var mappings = AutoMap.AssemblyOf<SecurableEntity>(new AutomappingConfiguration());
        mappings.Conventions.Setup(GetConventions());
        mappings.IgnoreBase<Entity>();
        mappings.IgnoreBase<SecurableEntity>();
        mappings.IgnoreBase(typeof(EntityWithTypedId<>));
        mappings.UseOverridesFromAssemblyOf<AutoPersistenceModelGenerator>();

        //mappings.UseOverridesFromAssemblyOf<UserMap>(); // Should call Override method of UserMap, but doesn't appear to...
        mappings.Override<User>(new UserMap().Override()); // This hack fixes the issue with calling the Override method of UserMap.
        mappings.UseOverridesFromAssemblyOf<UserMap>();

        return mappings;
    }

class UserMap : IAutoMappingOverride<User>
{
    public void Override(AutoMapping<User> mapping)
    {
        //mapping => mapping.Table("Users");
        mapping.Table("Users");
    }

    public Action<AutoMapping<User>> Override()
    {
        return map =>
            {
                map.Table("Users");
            };
    }
}

I've tried making various modifications to the configuration and pouring over internet articles on Fluent NHibernate, to no avail. I have a working version using Sharp Arch 1.x, and earlier versions of NHibernate and Fluent. I'm assuming that there has been a change in syntax that I'm missing. Any and all help would be greatly appreciated.

Thank you!
John

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不爱素颜 2024-12-17 21:52:25

流畅的 NHibernate 使用 Assembly.GetExportedTypes() 方法从给定程序集中获取所有重写。正如此方法的文档所述,它获取此程序集中定义的公共类型,这些类型在程序集外部可见。您的覆盖是隐式的内部。只需在 class UserMap 之前添加 public 即可。

Fluent NHibernate use Assembly.GetExportedTypes() method to get all the overrides from given assembly. As this method's documentation say, it gets the public types defined in this assembly that are visible outside the assembly. Your override is implicitly internal. Just add public before class UserMap and it'll work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文