TripSent和ReturnCode
我想在这些表格中进行左连接,比如
“在TripSent.ReturnCode = ReturnCode.Id上加入TripSent”
这是我的TripSent制图类
public TripSentMap()
{
ImportType<RemittanceDetailTransHeader>();
Schema(Dao.DataAccess.Schema);
Table("EI_TRIP_SENT");
LazyLoad();
Id(x => x.Id)
.Column("ID")
.CustomType("Int64")
.Access.Property()
.CustomSqlType("NUMBER")
.Not.Nullable()
.Precision(12)
.GeneratedBy.Sequence("EI_TRIP_SENT_ID_SEQ");
//EDIT : Removed redundant Mapping Info
References(x => x.ReturnCode)
.Class<ReturnCode>()
.Access.Property()
.Cascade.None()
.LazyLoad()
.Columns("EI_RETURN_CODE_ID");
}
这是我的HQL
String hql = @"SELECT ts.PartialTripNumber, ts.Sequence, ts.TagIssuer, ts.TagNumber, ts.DateTime, ts.PlazaNumber, ts.LaneNumber, ts.RealCategory, ts.DetectedCategory,
ts.TabulatedCategory, ts.Amount, ts.PassMode, ts.LicensePlate, ts.ImageReason, ts.ReturnCode, ts.TripSentStatus
FROM TripSent ts
WHERE ts.Remittance.Id = :remId";
var transactionDetailsHql = _session.CreateQuery(hql)
.SetParameter("remId", remId)
.List();
这会生成一个像这样的查询
select tripsent0_.PARTIAL_TRIP_NUMBER as col_0_0_,
tripsent0_.SEQUENCE as col_1_0_,
tripsent0_.EI_TAG_ISSUER_ID as col_2_0_,
tripsent0_.TAG_NUMBER as col_3_0_,
tripsent0_.DATE_TIME as col_4_0_,
tripsent0_.PLAZA_NUMBER as col_5_0_,
tripsent0_.LANE_NUMBER as col_6_0_,
tripsent0_.REAL_CATEGORY as col_7_0_,
tripsent0_.DETECTED_CATEGORY as col_8_0_,
tripsent0_.TABULATED_CATEGORY as col_9_0_,
tripsent0_.AMOUNT as col_10_0_,
tripsent0_.EI_PASS_MODE_ID as col_11_0_,
tripsent0_.LICENSE_PLATE as col_12_0_,
tripsent0_.EI_IMAGE_REASON_ID as col_13_0_,
tripsent0_.EI_RETURN_CODE_ID as col_14_0_,
tripsent0_.EI_TRIP_SENT_STATUS_ID as col_15_0_,
tagissuer1_.ID as ID36_0_,
passmode2_.ID as ID14_1_,
imagereaso3_.ID as ID12_2_,
returncode4_.ID as ID28_3_,
tripsentst5_.ID as ID48_4_,
tagissuer1_.DESCRIPTION as DESCRIPT2_36_0_,
tagissuer1_.EI_TAG_CHECK_TYPE_ID as EI3_36_0_,
tagissuer1_.EI_TAG_OSA_ID as EI4_36_0_,
passmode2_.DESCRIPTION as DESCRIPT2_14_1_,
imagereaso3_.DESCRIPTION as DESCRIPT2_12_2_,
returncode4_.DESCRIPTION as DESCRIPT2_28_3_,
tripsentst5_.DESCRIPTION as DESCRIPT2_48_4_
from CENTRO.EI_TRIP_SENT tripsent0_
inner join CENTRO.EI_TAG_ISSUER tagissuer1_
on tripsent0_.EI_TAG_ISSUER_ID = tagissuer1_.ID
inner join CENTRO.EI_PASS_MODE passmode2_
on tripsent0_.EI_PASS_MODE_ID = passmode2_.ID
inner join CENTRO.EI_IMAGE_REASON imagereaso3_
on tripsent0_.EI_IMAGE_REASON_ID = imagereaso3_.ID
inner join CENTRO.EI_RETURN_CODE returncode4_
on tripsent0_.EI_RETURN_CODE_ID = returncode4_.ID
inner join CENTRO.EI_TRIP_SENT_STATUS tripsentst5_
on tripsent0_.EI_TRIP_SENT_STATUS_ID = tripsentst5_.ID
where tripsent0_.EI_REMITTANCE_ID = 12 /* :p0 */
但是我想要一个LEFT OUTER JOIN而不是
inner join CENTRO.EI_RETURN_CODE returncode4_ on tripsent0_.EI_RETURN_CODE_ID = returncode4_.ID
我找不到怎么做 我也试过了映射
References(x => x.ReturnCode)
.Class<ReturnCode>()
.Access.Property()
.Cascade.None()
.NotFound.Ignore().Nullabe()
.Not.LazyLoad()
.Columns("EI_RETURN_CODE_ID");
没有成功D:
答案 0 :(得分:0)
您应该从映射中删除冗余信息,以便于阅读。
此外,像NHibernate这样的对象/关系映射器旨在从关系数据库返回对象。如果你试图指定类似LEFT JOIN的东西,那么你似乎不是想要拉一个对象,而是一些自定义视图。
您仍然可以执行此操作,但您需要一个数据传输对象(DTO),它基本上是一个对象,表示查询中的每一行将返回的内容。您仍然可以使用NHibernate的数据库连接并使用CreateSqlQuery
运行原始SQL,然后根据需要将结果转换为对象。
答案 1 :(得分:0)
在这种情况下,我需要编写一个纯SQL查询。但它是一个孤立的。