English 中文(简体)
氟化氮 Join with Constraint
原标题:Fluent NHibernate Join with Constraint

i 有一个实体,其适当性分布在两张表格中,即图示一个类别,使用NHibernate,但限制合并表格。

i 立即将我的问题范围改变,把这个问题变成了宝贵的客户领域,因此,我在这里的例子可能会引起一点争议,但它表明了我的问题。 基本如此;即有一个客户表,其中有一些客户属性,但客户的第一和最后的名字则在单独的客户表中作为与客户有联系的两行,并被确定为第一和最后的名称。

下表图表如下:

CREATE TABLE Customer( CustomerId int, Birthday datetime )

CREATE TABLE CustomerName( CustomerId int NOT NULL, CustomerNameTypeId int NOT NULL, Name nvarchar(25) NOT NULL )

CREATE TABLE CustomerNameTypes( CustomerNameTypeId NOT NULL, Description nvarchar(25) NOT NULL )

with the CustomerNameTypes table containing two rows: 1, "FirstName" 2, "SecondName"

我们需要的是图形图象,将上面图示如下:

public class Customer
{
    public virtual int CustomerId { get; set; }
    public virtual string FirstName { get; set; }
    public virtual string LastName { get; set; }
    public virtual DateTime Birthday { get; set; }
}

谁能帮助?

many thanks in advance Chris Browne

问题回答

能够真正地以自由的方式回答这个问题,但我几乎没有其他可能帮助你解决问题的办法!

  1. 我本人将重写如下 s:

    select 
          c.CustomerId, 
          c.Birthday, 
          fn.Name, 
          ln.Name
    from Customer c
    left join CustomerName fn on c.CustomerId = fn.CustomerId
    left join CustomerNameTypes fnt on fnt.CustomerNameTypeId = fn.CustomerNameTypeId
          and fnt.[Description] =  First 
    left join CustomerName ln on c.CustomerId = ln.CustomerId 
    left join CustomerNameTypes lnt on lnt.CustomerNameTypeId = ln.CustomerNameTypeId
          and lnt.[Description] =  Last 
    

    这可能有助于你在继续使用NHibernate时解决。

  2. 另一种选择是使用一种观点。 我个人使用LLBLGenPro,在Linq获得第2.6号申诉之前,这是我偏好的办法,能够迅速和方便地解决棘手的问题。

  3. 这将是我难以想象的,特别是如果你有一个顽固的德国律师协会,或者它是一个第三方银行! 数据库不合时宜。 这种结构过于正常,是你处理这一问题的整个原因。

不管怎么说,我知道它不是具体回答你的问题,但我希望你们会从中得到一些用!

仅此刻,就等于:

select c.CustomerId, c.Birthday, fn.Name, ln.Name
from Customer c
  left join CustomerName fn on c.CustomerId = fn.CustomerId and fn.CustomerNameTypeId = (select CustomerNameTypeId from CustomerNameTypes where Description =  First )
  left join CustomerName ln on c.CustomerId = ln.CustomerId and ln.CustomerNameTypeId = (select CustomerNameTypeId from CustomerNameTypes where Description =  Last )

che!





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签