错误:流畅的 NHibernate 映射引用了不同程序集中的映射

发布于 2024-11-13 00:07:15 字数 3107 浏览 4 评论 0原文

我的公司有多个站点引用相同的数据库和核心代码库。 然后我们有一个 CMS 来管理数据。

在核心库中,我有一个 Site 类,其中包含有关每个站点的大量基本信息。这是我的流畅映射。

using Core.Model;  // Where Site class exists

namespace Core.Repository.NHibernate.Mappings
{
    public class SiteMapping : ClassMap<Site>
    {
        public SiteMapping()
        {
            Table("f_site");
            Id(x => x.Id, "f_site_id").GeneratedBy.Identity();
            Map(x => x.Domain, "domain_name").Not.Nullable();
        }
    }
}

作为 CMS 的一部分,我们会记录谁编辑了什么内容以及何时编辑的日志。但我只想在 CMS 中引用 Log 类和映射,而不是在我的核心代码中,因为人们只能通过 CMS 编辑信息。

这是我当前到 Log 类的流畅映射,它引用了 Site 类。

using Core.Model; // where Site class exists
using Cms.Model; // where Log and CmsUser classes exists

namespace Cms.Repository.NHibernate.Mappings
{
    public class LogMapping : ClassMap<Log>
    {
        public LogMapping()
        {
            Table("f_log");
            Id(x => x.Id, "f_log_id").GeneratedBy.Identity();
            Map(x => x.Message, "message");
            Map(x => x.LogType, "d_log_type_id").CustomType<LogType>();
            Map(x => x.LogOperation, "d_log_operation_id").CustomType<LogOperation>();
            Map(x => x.Date, "log_date");

            References<Site>(x => x.Site, "f_site_id")
                .ForeignKey("f_site_id")
                .Cascade.None();

            References<CmsUser>(x => x.User, "userId")
                .ForeignKey("userId")
                .Cascade.None();
        }
    }
}

理论上这很好用,但是日志映射错误如下

Cms.Tests.Repository.NHibernate.Repository.TestLogRepository.TestLogMappings:
StructureMap.StructureMapException : StructureMap Exception Code:  207
Internal exception while creating Instance 'e46153a3-2bfe-4279-8749-a42d7a6dd10c' of PluginType Core.Repository.NHibernate.SessionStorage.ISessionContainer`1[[HbmCms.Repository.NHibernate.Mappings.Config.LogMapping, Cms.Repository.NHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], Core.Repository.NHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.  Check the inner exception for more details.
  ----> StructureMap.StructureMapException : StructureMap Exception Code:  207
Internal exception while creating Instance '9e72c2ff-e3f4-4b54-9f34-3422a7b982a7' of PluginType Core.Repository.NHibernate.SessionStorage.ISessionFactoryContainer`1[[Cms.Repository.NHibernate.Mappings.Config.LogMapping, Cms.Repository.NHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].  Check the inner exception for more details.
  ----> FluentNHibernate.Cfg.FluentConfigurationException : An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.


  ----> NHibernate.MappingException : An association from the table f_log refers to an unmapped class: Core.Model.Site

有人知道如何让我的 CMS 映射引用核心站点映射吗?这是获取两个项目之间的映射的第一段代码,但我们将做相当多的事情,因为很多事情您只能在 CMS 中查看和执行。如果可以避免的话,我真的不想将仅 CMS 的代码放入核心库中。

帮助

感谢桑德拉的

My company has multiple sites which reference the same DB and Core library of code.
Then we have a CMS which manages the data.

In the Core library I have a Site class which holds a bunch of basic info about each site. This is the fluent mapping I have for it.

using Core.Model;  // Where Site class exists

namespace Core.Repository.NHibernate.Mappings
{
    public class SiteMapping : ClassMap<Site>
    {
        public SiteMapping()
        {
            Table("f_site");
            Id(x => x.Id, "f_site_id").GeneratedBy.Identity();
            Map(x => x.Domain, "domain_name").Not.Nullable();
        }
    }
}

As part of the CMS, we keep a log of who edited what and when. But I want to only have a reference to the Log class and mapping in the CMS, rather than in my core code, as people can only edit info via the CMS.

Here is my current fluent mapping to the Log class, which referneces the Site class.

using Core.Model; // where Site class exists
using Cms.Model; // where Log and CmsUser classes exists

namespace Cms.Repository.NHibernate.Mappings
{
    public class LogMapping : ClassMap<Log>
    {
        public LogMapping()
        {
            Table("f_log");
            Id(x => x.Id, "f_log_id").GeneratedBy.Identity();
            Map(x => x.Message, "message");
            Map(x => x.LogType, "d_log_type_id").CustomType<LogType>();
            Map(x => x.LogOperation, "d_log_operation_id").CustomType<LogOperation>();
            Map(x => x.Date, "log_date");

            References<Site>(x => x.Site, "f_site_id")
                .ForeignKey("f_site_id")
                .Cascade.None();

            References<CmsUser>(x => x.User, "userId")
                .ForeignKey("userId")
                .Cascade.None();
        }
    }
}

In theory this works great, but the Log mapping errors with the following

Cms.Tests.Repository.NHibernate.Repository.TestLogRepository.TestLogMappings:
StructureMap.StructureMapException : StructureMap Exception Code:  207
Internal exception while creating Instance 'e46153a3-2bfe-4279-8749-a42d7a6dd10c' of PluginType Core.Repository.NHibernate.SessionStorage.ISessionContainer`1[[HbmCms.Repository.NHibernate.Mappings.Config.LogMapping, Cms.Repository.NHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], Core.Repository.NHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.  Check the inner exception for more details.
  ----> StructureMap.StructureMapException : StructureMap Exception Code:  207
Internal exception while creating Instance '9e72c2ff-e3f4-4b54-9f34-3422a7b982a7' of PluginType Core.Repository.NHibernate.SessionStorage.ISessionFactoryContainer`1[[Cms.Repository.NHibernate.Mappings.Config.LogMapping, Cms.Repository.NHibernate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].  Check the inner exception for more details.
  ----> FluentNHibernate.Cfg.FluentConfigurationException : An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.


  ----> NHibernate.MappingException : An association from the table f_log refers to an unmapped class: Core.Model.Site

Does anyone have any idea how to get my CMS mapping to reference the Core Site mapping? This is the first bit of code that is getting a mapping across two projects, but its something that we'll be doing a fair bit of, as lots of stuff you only look at and do in the CMS. I don't really want to put the CMS only code into the Core library if i can avoid it.

Thanks for the help

Sandra

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

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

发布评论

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

评论(1

耳钉梦 2024-11-20 00:07:15

“未映射的类”错误通常源于配置没有记录该 ClassMap。

在您的 FluentConfiguration 中,您可能有类似的内容:

.Mappings(m => m.FluentMappings
                .AddFromAssemblyOf<T>())

看来您的两个 ClassMap(至少是帖子中提到的那些)位于不同的程序集中。您可以使用以下方式指定多个程序集:

.Mappings(m => m.FluentMappings
                .AddFromAssemblyOf<T1>()
                .AddFromAssemblyOf<T2>())

要准确查看正在映射的内容,您可以添加

.Diagnostics(d => d.Enable().OutputToConsole())

到 FluentConfiguration 中,它将返回类映射、应用于它们的约定以及它们有效的原因/原因。

An 'unmapped class' error usually stems from the Configuration not having that ClassMap recorded.

In your FluentConfiguration, you probably have something similar to:

.Mappings(m => m.FluentMappings
                .AddFromAssemblyOf<T>())

It appears that your two ClassMaps (at least those mentioned in the post) are in different assemblies. You can specify multiple assemblies with:

.Mappings(m => m.FluentMappings
                .AddFromAssemblyOf<T1>()
                .AddFromAssemblyOf<T2>())

To see exactly what is being mapped, you can add

.Diagnostics(d => d.Enable().OutputToConsole())

to your FluentConfiguration and it will return the class maps, the conventions applied to them and why/why not they were valid.

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