你如何在 Hibernate ActiveRecord 中进行连接?

发布于 2024-08-03 13:59:06 字数 1467 浏览 3 评论 0原文

我如何进行一个连接,它会返回类似于 -

SELECT * FROM Project LEFT JOIN ProjectRegion ON ProjectRegion.id = Project.projectRegion

我当前使用的语法 -

  Project[] projects = Project.FindAll();

我的表是使用 ActiveRecord/hibernate 设置的,如下所示 -

    [ActiveRecord]
    public class ProjectRegion : ActiveRecordBase<ProjectRegion>
    {
        private int id;
        private String title;

        public ProjectRegion()
        {
        }

        [PrimaryKey]
        public int Id
        {
            get { return id; }
            set { id = value; }
        }

        [Property]
        public String Title
        {
            get { return title; }
            set { title = value; }
        }
    }


    [ActiveRecord]
    public class Project : ActiveRecordBase<Project>
    {
        private int id;
        private String projectNumber;
        private String projectRegion;

        public Project()
        {
        }

        [PrimaryKey]
        public int Id
        {
            get { return id; }
            set { id = value; }
        }

        [Property]
        public String ProjectInternalCode
        {
            get { return projectNumber; }
            set { projectNumber = value; }
        }

        [Property]
        public String ProjectRegion
        {
            get { return projectRegion; }
            set { projectRegion = value; }
        }
...

How do I do a join that would return me results similar to-

SELECT * FROM Project LEFT JOIN ProjectRegion ON ProjectRegion.id = Project.projectRegion

I currently use the syntax-

  Project[] projects = Project.FindAll();

My tables are setup with ActiveRecord/hibernate as follows -

    [ActiveRecord]
    public class ProjectRegion : ActiveRecordBase<ProjectRegion>
    {
        private int id;
        private String title;

        public ProjectRegion()
        {
        }

        [PrimaryKey]
        public int Id
        {
            get { return id; }
            set { id = value; }
        }

        [Property]
        public String Title
        {
            get { return title; }
            set { title = value; }
        }
    }


    [ActiveRecord]
    public class Project : ActiveRecordBase<Project>
    {
        private int id;
        private String projectNumber;
        private String projectRegion;

        public Project()
        {
        }

        [PrimaryKey]
        public int Id
        {
            get { return id; }
            set { id = value; }
        }

        [Property]
        public String ProjectInternalCode
        {
            get { return projectNumber; }
            set { projectNumber = value; }
        }

        [Property]
        public String ProjectRegion
        {
            get { return projectRegion; }
            set { projectRegion = value; }
        }
...

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

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

发布评论

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

评论(1

挖鼻大婶 2024-08-10 13:59:06

如果您将 Project 类中的 ProjectRegion 属性声明为 ProjectRegion 类型而不是字符串类型,则当 NHibernate 获取 Project 时,它将自动连接(根据获取策略)ProjectRegion 表。

If you declare the ProjectRegion property in the Project class to be of type ProjectRegion instead of string, when NHibernate fetches a Project it will automatically join (according to a fetch policy) the ProjectRegion table.

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