2009-09-03 47 views
0

我怎麼聯接,將返回我的結果類似於TO-你如何在hibernate activerecord中加入?

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

我目前使用的syntax-

Project[] projects = Project.FindAll(); 

我的表是建立與ActiveRecord的/休眠如下 -

[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; } 
     } 
... 
+0

不應該在Project類中的ProjectRegion屬性的類型是ProjectRegion而不是字符串? – 2009-09-03 14:03:39

+0

好吧,這是有道理的,但仍然不會做聯合會嗎? – wkstar 2009-09-03 14:07:27

回答

1

如果你將Project類中的ProjectRegion屬性聲明爲類型爲ProjectRegion而不是字符串,當NHibernate獲取一個Project時,它將au按照提取策略自動加入ProjectRegion表。

+0

我這樣做了,必須將[Property]更改爲[BelongsTo(「ProjectRegion」)],現在它可以工作。 美麗,謝謝! – wkstar 2009-09-03 14:26:53