FluentNHibernate 需要映射语法帮助

发布于 2024-10-13 20:13:11 字数 1550 浏览 1 评论 0原文

我在为以下数据模型和域对象找出适当的 FluentNHibernate 映射语法时遇到一些麻烦。这是我正在使用的数据模型: 在此处输入图像描述

我正在尝试将以下域对象映射到该模型:

namespace FluentNHibernateSandbox.Entities
{
    public abstract class EntityBase
    {
        public virtual long Id { get; set; }
    }
}

namespace FluentNHibernateSandbox.Entities
{
    public class Attribute : EntityBase
    {
        public virtual string Name { get; set; }
        public virtual string Label { get; set; }
        public virtual string Description { get; set; }
        public virtual int SortOrder { get; set; }
        public virtual Group Group { get; set; }
        public virtual Editor Editor { get; set; }
    }
}

namespace FluentNHibernateSandbox.Entities
{
    public class Group : EntityBase
    {
        public virtual string Name { get; set; }
        public virtual string Label { get; set; }
        public virtual string Description { get; set; }
        public virtual int SortOrder { get; set; }
        public virtual IList<Attribute> Attributes { get; set; }
    }
}

namespace FluentNHibernateSandbox.Entities
{
    public class Editor : EntityBase
    {
        public virtual string ViewName { get; set; }
        public virtual string WorkerClassName { get; set; }
    }
}

一般来说,我最终想要什么看起来似乎并不那么难做到,但是在尝试了我能想到的几乎所有映射组合之后,我似乎仍然无法做到正确。我只需要我的属性有一个对其所属组的引用以及对分配给它的编辑器的引用,并且每个组应该有一个属于它的属性的集合。这几个多对多连接表似乎让我感到不舒服。特别是 APPLICATION_ATTRIBUTE 表。最终我只想要我的应用程序所关心的属性,在本例中是 APPLICATION_ID 为 4 的属性。

任何帮助将不胜感激。谢谢。

I'm having some trouble figuring out the appropriate FluentNHibernate mapping syntax for the following data model and domain objects. Here's the data model I'm working against:
enter image description here

And I'm trying to map the following domain objects to that model:

namespace FluentNHibernateSandbox.Entities
{
    public abstract class EntityBase
    {
        public virtual long Id { get; set; }
    }
}

namespace FluentNHibernateSandbox.Entities
{
    public class Attribute : EntityBase
    {
        public virtual string Name { get; set; }
        public virtual string Label { get; set; }
        public virtual string Description { get; set; }
        public virtual int SortOrder { get; set; }
        public virtual Group Group { get; set; }
        public virtual Editor Editor { get; set; }
    }
}

namespace FluentNHibernateSandbox.Entities
{
    public class Group : EntityBase
    {
        public virtual string Name { get; set; }
        public virtual string Label { get; set; }
        public virtual string Description { get; set; }
        public virtual int SortOrder { get; set; }
        public virtual IList<Attribute> Attributes { get; set; }
    }
}

namespace FluentNHibernateSandbox.Entities
{
    public class Editor : EntityBase
    {
        public virtual string ViewName { get; set; }
        public virtual string WorkerClassName { get; set; }
    }
}

In general, what I ultimately want doesn't seem like it should be all that hard to do, but I after having tried just about every combination of mappings I can think of, I still can't seem to get it right. I just need my Attribute to have a reference to the Group that it belongs to and a reference to the Editor assigned to it, and each Group should have a collection of the Attributes that are part of it. The couple of many-to-many join tables are what seem to be giving me fits. Particularly the APPLICATION_ATTRIBUTE table. Ultimately I only want the Attributes that my application is concerned with, in this case, those with an APPLICATION_ID of 4.

Any help would be greatly appreciated. Thanks.

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

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

发布评论

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

评论(1

余生共白头 2024-10-20 20:13:11

真的有点惊讶没有人对此做出回应,但无论如何。我们提出的这种映射情况的答案/解决方案是在数据库中创建一些自定义视图,将所有视图连接在一起,这是我一开始试图避免的,但事实证明这确实是最好的方法。我需要的特定于应用程序的数据,然后将应用程序的域对象映射到这些视图。这至少部分有效,因为我从这些表中需要的信息对于该应用程序来说是只读的,但即使我需要写入表,我也很确定(尽管还没有验证,因为我没有验证)在这种情况下确实不需要)我可以将我的视图设置为可写,这也可以工作。

向@robconery致敬

Really kinda surprised nobody responded to this at all, but anyway. The answer/solution for this mapping situation that we came up with, which I was trying to avoid to start with, but turned out to really be the best way to go, was to create some custom views in the database that joined together all of the application-specific data I needed, and then just mapped my application's domain objects to those views. This worked at least partially because the information I needed from these tables is going to be read-only for this application, but even if I needed to write to the tables, I'm pretty sure (though haven't verified as I didn't really have need in this case) that I could have setup my views to be writeable and that would've worked too.

Hat tip to @robconery.

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