将三重连接映射到 nhibernate。 (设计奇怪的旧数据库)

发布于 2024-11-26 18:59:05 字数 852 浏览 1 评论 0原文

我正在努力将用 powerbuilder 编写的旧应用程序转换为 .NET 应用程序。在此过程中,我们使用旧数据库,并且 powerbuilder 应用程序中使用的一些查询很难转换为 nhibernate 流畅映射(至少对我来说)。

我有以下 sql 来获取位列表:

SELECT   MYSCHEME.BIT.BIT_S,
         MYSCHEME.BIT.BIT_NAME,
         MYSCHEME.BIT.BIT_TYPE,   
         MYSCHEME.BIT.BIT_SIZE,                     
         MYSCHEME.BS.BS_NAME,    
         MYSCHEME.CMS.WHOLE_S

FROM MYSCHEME.BIT join MYSCHEME.BS on ( MYSCHEME.BIT.BS_S = MYSCHEME.BS.BS_S ) 
left outer join MYSCHEME.OF on MYSCHEME.BIT.BIT_TYPE_S = MYSCHEME.OF.F_S 
left outer join MYSCHEME.CMS on MYSCHEME.OF.OF_S = MYSCHEME.CMS.PART_S
WHERE ( MYSCHEME.BS.BS_S = 25) 

我应该如何将其映射到 nhibernate?我应该使用条件和联接,还是只是将其映射到对其他表的引用?另一个挑战是数据库中的关键约束非常少,例如BIT和OF、CMS和OF之间没有关键约束。

有人知道如何解决这个挑战吗?我还必须能够更新 CMS.WHOLE_S。

第一次加入 BS 表并不是很重要,因为它只是为了获取“父”信息,我可以从应用程序中的其他部分访问该信息。

I am working on converting an old app written in powerbuilder to a .NET app. In this process we work with an old database, and some of the queries used in the powerbuilder app is quite challenging to convert into nhibernate fluent mapping (for me at least).

I have the following sql to get a list of bits:

SELECT   MYSCHEME.BIT.BIT_S,
         MYSCHEME.BIT.BIT_NAME,
         MYSCHEME.BIT.BIT_TYPE,   
         MYSCHEME.BIT.BIT_SIZE,                     
         MYSCHEME.BS.BS_NAME,    
         MYSCHEME.CMS.WHOLE_S

FROM MYSCHEME.BIT join MYSCHEME.BS on ( MYSCHEME.BIT.BS_S = MYSCHEME.BS.BS_S ) 
left outer join MYSCHEME.OF on MYSCHEME.BIT.BIT_TYPE_S = MYSCHEME.OF.F_S 
left outer join MYSCHEME.CMS on MYSCHEME.OF.OF_S = MYSCHEME.CMS.PART_S
WHERE ( MYSCHEME.BS.BS_S = 25) 

How should i map this into nhibernate? Should i use criteria and joins, or just map it with references to other tables? An other challenge is that there are very few key constrains in the database, for example there is no key constraint between BIT and OF, or CMS and OF.

Anyone has a good idea of how to solve this challenge? I must also be able to update CMS.WHOLE_S.

The first join to the BS table is not very important, since it is only to get the "parent" information, i can access that information from other parts in my application.

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

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

发布评论

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

评论(1

陈年往事 2024-12-03 18:59:05
class Bit
{
    public virtual BS Bs { get; set; }
    public virtual int WholeS
    {
        get { return Bs.Of.CMS.WholeS; }
        set { Bs.Of.CMS.WholeS = value; }
    }
}

class BS
{
    public virtual Of Of { get; set; }
}

class Of
{
    public virtual CMS CMS { get; set; }
}

class CMS
{
    public virtual int WholeS { get; set; }
}

class BitMap : ClassMap<Bit>
{
    public BitMap()
    {
        References(bit => bit.Bs, "BS_S")
            .Not.LazyLoad();  // should take care, that all is join-loaded
    }
}
...

Bit bit = session.Get<Bit>(25);
int wholeS = bit.Bs.Of.CMS.WholeS;

奥德

Bit bit = session.Get<Bit>(25);
int wholeS = bit.WholeS;
class Bit
{
    public virtual BS Bs { get; set; }
    public virtual int WholeS
    {
        get { return Bs.Of.CMS.WholeS; }
        set { Bs.Of.CMS.WholeS = value; }
    }
}

class BS
{
    public virtual Of Of { get; set; }
}

class Of
{
    public virtual CMS CMS { get; set; }
}

class CMS
{
    public virtual int WholeS { get; set; }
}

class BitMap : ClassMap<Bit>
{
    public BitMap()
    {
        References(bit => bit.Bs, "BS_S")
            .Not.LazyLoad();  // should take care, that all is join-loaded
    }
}
...

Bit bit = session.Get<Bit>(25);
int wholeS = bit.Bs.Of.CMS.WholeS;

oder

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