我试图在 Nhibernate 中创建的查询:
SELECT _Eligible_Claims.ClaimID, _Eligible_Claims.DateFilled, _Eligible_Claims.NDC, _Eligible_Claims.Cost
From _Eligible_Claims
INNER JOIN _Files_Claims ON _Files_Claims.FileID = _Eligible_Claims.FileID
_Eligible_Claims 是一个视图(因此它没有键),_Files_Claims 的 PK 为“FileID”。
Eligible_Claims 地图:
public EligibleClaimsMap()
{
ReadOnly();
Table("_Eligible_Claims");
Id(x => x.UniqueIdentifier, "Id")
.GeneratedBy.Guid();
Map(x => x.ApplicationID, "ApplicationID")
.Not.Nullable();
Map(x => x.BenOp, "BenOp")
.Not.Nullable();
Map(x => x.BenOpID, "BenOpID")
.Not.Nullable();
Map(x => x.MemberID, "MemberID")
.Nullable();
Map(x => x.ClaimID, "ClaimID")
.Not.Nullable();
Map(x => x.NDC, "NDC")
.Not.Nullable();
Map(x => x.DateFilled, "DateFilled")
.Not.Nullable();
Map(x => x.Cost, "Cost")
.Not.Nullable();
Map(x => x.DrugID, "DrugId")
.Nullable();
Map(x => x.CategoryID, "CategoryId")
.Nullable();
Map(x => x.FileID, "FileID")
.Not.Nullable();
}
_Files_Claims 映射:
public ClamFileMap()
{
Table("_Files_Claims");
Id(x => x.ID, "FileID")
.CustomType<UintToInt>()
.GeneratedBy.Identity();
Map(x => x.Filename, "FileName")
.Not.Nullable();
Map(x => x.Size, "FileSize")
.Not.Nullable();
Map(x => x.DateCreated, "DateCreated")
.Not.Nullable();
Map(x => x.DateEntered, "DateEntered")
.Not.Nullable();
Map(x => x.ClientID, "ClientID")
.Not.Nullable()
.CustomType<UintToInt>();
Map(x => x.MasterTable, "MasterTable")
.Nullable();
Map(x => x.GUID, "GUID")
.Nullable();
Map(x => x.Protected, "Protected")
.Not.Nullable();
Map(x => x.BatchTimeStamp, "BatchTimeStamp")
.Nullable();
Map(x => x.ApplicationID, "ApplicationID")
.Nullable();
Map(x => x.ClaimCount, "Claims")
.Not.Nullable();
Map(x => x.TotalCost, "ClaimCost")
.Not.Nullable();
Map(x => x.PackageID, "PackageID")
.Nullable();
Map(x => x.TempDate, "TempDate")
.Nullable();
Map(x => x.Renamed, "Renamed")
.Not.Nullable();
Map(x => x.ERRPPackage, "ERRPPackage")
.Not.Nullable();
Map(x => x.Removed, "Removed")
.Not.Nullable();
Map(x => x.RemovedBy, "RemovedBy")
.Nullable();
Map(x => x.RemovedDate, "RemovedDate")
.Nullable();
Map(x => x.ImportedBy, "ImportedBy")
.Nullable();
Map(x => x.ImportedDate, "ImportedDate")
.Nullable();
Map(x => x.ControlTotal, "ControlTotal")
.Nullable();
}
我目前的做法:
var query = session.CreateCriteria<EligibleClaims>()
.CreateAlias("ClaimFile", "claimFile", NHibernate.SqlCommand.JoinType.InnerJoin);
我不希望这会起作用,因为默认情况下它不会尝试在 ClaimFile 的 FK 上加入 EligibleClaims 的 PK 吗?我注意到“CreateAlias”方法有一个名为“withClause”的“ICriterion”的第四个参数的重载。知道如何实现吗?或者我应该从另一个角度来解决这个问题?