具有投影的多态nhibernate查询

时间:2010-12-02 15:01:34

标签: nhibernate

将单个表用于类层次结构我想使用投影来展平层次结构,以向用户显示结果列表。

有没有办法使用HQL或Criteria API执行此操作,而无需发出多个单独的查询或联合?


public class A {
    public virtual long Id { get; set; }
}

public class B : A {
    public virtual DateTime SomeDate { get; set; }
    public virtual OtherEntity Other { get; set; }
}

public class C : A {
    public virtual DateTime? SomeDate { get; set; }
    public virtual string Description { get; set; }
}

public class D : A {
    public virtual string Description { get; set; }
}

public class OtherEntity {
    public virtual string Name { get; set; }
}

SQL表:

CREATE TABLE Items (
    Id bigint NOT NULL PRIMARY KEY,
    Kind char(1) NOT NULL,
    SomeDate datetime NULL,
    Description NULL
)

CREATE TABLE OtherEntity (
    Id bigint NOT NULL PRIMARY KEY,
    Name nvarchar(255) NOT NULL
)

输出预测:

public class ItemReport {
    // From A.Id
    public virtual long Id { get; set; }

    // From B.SomeDate or C.SomeDate
    public virtual DateTime? SomeDate { get; set; }

    // From C.Description or D.Description
    public virtual string Description { get; set; }

    // From B.OtherEntity.Name
    public virtual string OtherName { get; set; }
}

0 个答案:

没有答案