我使用Fluent-Nhibernate版本1.3,並試圖使查詢包含5個表。我創建了一個Oracle數據庫的SQL查詢,我試圖用linq-to-nhibernate進行復制。Linq-to-Nhibernate倍數加入條件
下面是我的實體和映射的示例。
實體:
public class A
{
public virtual int idA { get; set; }
public virtual String codA { get; set; }
public virtual String tipoA { get; set; }
public virtual IList<B> listB { get; set; }
}
public class B
{
public virtual C objectC { get; set; }
public virtual A objectA { get; set; }
public virtual DateTime dtBegin { get; set; }
public virtual DateTime dtEnd { get; set; }
}
public class C
{
public virtual int idC { get; set; }
public virtual String codeC { get; set; }
public virtual IList<B> listB { get; set; }
public virtual IList<D> listD { get; set; }
}
public class D
{
public virtual C objectC { get; set; }
public virtual string flgD { get; set; }
public virtual DateTime dtBegin { get; set; }
public virtual DateTime dtEnd { get; set; }
public virtual E objectE { get; set; }
}
public class E
{
public virtual int idE { get; set; }
public virtual String dsE { get; set; }
public virtual DateTime dtBegin { get; set; }
public virtual DateTime dtEnd { get; set; }
public virtual IList<D> listD { get; set; }
}
我的映射:
class AMap : ClassMap<A>
{
public AMap()
{
Table("A");
Id(x => x.idA, "ID_A").GeneratedBy.Sequence("StringA");
Map(x => x.tipoA, "TP_A");
Map(x => x.codA, "CODE_A");
HasMany(x => x.listB).Cascade.All().KeyColumn("ID_A");
}
}
class BMap : ClassMap<B>
{
public BMap()
{
Table("B");
CompositeId()
.KeyReference(x => x.objectC, "ID_C")
.KeyReference(x => x.objectA, "ID_A")
.KeyProperty(x => x.dtBegin, "DT_BEGIN");
Map(x => x.dtEnd, "DT_END");
}
}
class CMap : ClassMap<C>
{
public CMap()
{
Table("C");
Id(x => x.idC, "ID_C").GeneratedBy.Sequence("StringC");
Map(x => x.codeC, "CODE_C");
HasMany(x => x.listB).Cascade.All().KeyColumn("ID_C");
HasMany(x => x.listD).Cascade.All().KeyColumn("ID_D");
}
}
class DMap : ClassMap<D>
{
public DMap()
{
Table("D");
CompositeId()
.KeyReference(x => x.objectC, "ID_C")
.KeyProperty(x => x.flgD, "FLG_D")
.KeyProperty(x => x.dtBegin, "DT_BEGIN");
References(x => x.objectE, "CODE_E");
Map(x => x.dtEnd, "DT_END");
}
}
class EMap : ClassMap<E>
{
public EMap()
{
Table("E");
Id(i => i.idE, "ID_E").GeneratedBy.Assigned();
Map(m => m.dsE, "DSC_E");
Map(m => m.dtBegin, "DT_BEGIN");
Map(m => m.dtEnd, "DT_END");
HasMany(x => x.listD).Cascade.All().KeyColumn("ID_E");
}
}
我的SQL查詢(它的工作原理):
SELECT C.CODE_C, E.CODE_E, E.DT_BEGIN
FROM TABLEA A, TABLEB B, TABLEC C, TABLED D, TABLEE E
WHERE A.CODE_A = '0000' AND A.ID_A = B.ID_A AND B.ID_C = C.ID_C AND B.DT_END IS NULL
AND C.ID_C = D.ID_C AND D.DT_END IS NULL AND D.CODE_E = E.CODE_E AND E.DT_END IS NULL;
我嘗試使用多個連接,但隨後一些relathionship是集合所以我將不得不在聯合內部做出一個地方。
所以我的問題是:有可能使這個相同的SQL查詢作爲linq-to-nhibernate或更好地做出一個選擇序列?不,我不能改變數據庫。
在此先感謝。
如果我讀這一權利, A> B是很多對B> C是一對多,C> D是多對一,D> E是多對一。我有沒有得到那個權利? – Bytemaster
嗨Bytemaster A> B oneToMany。 –