nhibernate가 sql을 생성 할 때 테이블에 대해 생성 될 별칭을 예측하는 방법이 있습니까?NHibernate - SQL 테이블 별칭이 일치하지 않습니다.
이론적으로 'this_', 'this_1_'등이되어야하며 멋질 것입니다.하지만 매핑에서 Join을 사용할 때 조금 더 임의적이라는 것을 발견했습니다.
통합 테스트의 예를 들어 내가 이런 걸 받고 있어요 :
table1 this_
left outer join
table2 o this_1_
on this_.id=this_1_.t1id
left outer join
table3 this_2_
on this_.id=this_2_.t1id
left outer join
table4 this_3_
on this_.id = this_3_.t1id
left outer join
table5 somealiasbasedonrootentity_2_
on this_.id=somealiasbasedonrootentity_2_.t1id
을하지만 난 웹 서버에서 동일한 매핑을 실행할 때 ... 모든 별명, somealias_ somealias_1_ 등
Shouldn 있습니다 최소한 ... 일관성 있니?
이 매핑 내에서--- 편집 '곳'또는 '식'의 어떤 종류를 사용하는 정말 열심히 (심지어 불가능)하게
: 내가 매핑 달성하고자하는 샘플 쿼리를
select
t1.a, t2.a, (select max(t3.value) where t3.id=t2.t3id)
from table1 t1
left join table2.t2 on t2.t1id=t1.id;
--- (거의 최신) 매핑은 다음과 같습니다. 나는 그것이 상당히 크다는 것을 알고 있지만, 나는보고 목적으로 만들 예정이었습니다. 당신이 클래스에 대한 FluentNHibernate 매핑이있는 경우
public class ClaimHistoryMap : ClassMap<ClaimHistory>
{
public ClaimHistoryMap()
{
Table("wts_claim");
ReadOnly();
Not.LazyLoad();
Id(x => x.Id, "claimid");
Map(x => x.ClaimNo, "claimNo");
Map(x => x.DateCompleted, "ModificationDate");
Map(x => x.DateOfDispatch, "DateOfDispatch");
Map(x => x.DateProcessed, "ModificationDate");
Map(x => x.Status, "status");
Map(x => x.WorkOrderNo, "ServiceWorkOrder");
Map(x => x.SerialNo, "serialNo");
Map(x => x.IsEnabled, "bStatus");
Map(x => x.InvoiceNo, "InvoiceNo");
Map(x => x.ServiceCoverage).Formula(
@"(Select c.coveragename from wts_servicecoverage as c where c.servicecoverageid=servicecoverageid)");
Join("wts_site_info",x=>
{
x.Optional().KeyColumn("claimid");
x.Map(s => s.CustomerName, "CustomerName");
x.Map(s => s.CustomerAddress, "Address");
x.Map(s => s.CustomerCity, "City");
x.Map(s => s.CustomerPhone, "Phone");
x.Map(s => s.CustomerZip, "Zip");
x.Map(s => s.ReportComplaint, "Complaint");
x.Map(s => s.TechnicianName, "TechName");
x.Map(s => s.Model)
.Formula(@"(Select mo.Model from WTS_Product mo where mo.ProductId=this_1_.ProductId)");
x.Map(s => s.CustomerState)
.Formula(@"(Select st.statename from wts_state st where st.stateid=this_1_.state)");
});
Join("wts_grand_total", x =>
{
x.Optional().KeyColumn("claimid");
x.Map(s => s.TotalCharge, "total");
x.Map(s => s.FreightCharge, "Frieght");
x.Map(s => s.PartsCharge, "Parts");
x.Map(s => s.HandlingFee, "Handling");
x.Map(s => s.SalesTax, "Mix");
});
Join("wts_labour_travel", x =>
{
x.Optional().KeyColumn("claimid");
x.Map(s => s.TravelCharge).Formula("traveltotal+travelovertotal+MilageRegular+MilageOvertime+supmileagehour+supmileageoverhour");
x.Map(s => s.TravelTime).Formula("TravelHourRegular+TravelHourOvertime+suptravelhour+suptraveloverhour");
x.Map(s => s.LaborCharge).Formula("labortotal+laborovertotal");
x.Map(s => s.LaborTime).Formula("LaborHoursRegular+LaborHoursOvertime+suplaborhour+suplaboroverhour");
x.Map(s => s.TripsNo, "trips");
x.Map(s => s.TruckCharge).Formula(
"(select max(ltr.TruckRate) from wts_labour_travel_rate ltr where ltr.LabourTravelId = this_3_.LabourTravelId)");
});
Map(x => x.WasModified).Formula(
"(select count(comm.claim_id) from wts_claim_status comm where comm.claim_id=this_.claimid and comm.Status=3)");
References(x => x.User, "entryBy").Fetch.Join().Not.LazyLoad();
HasMany(x => x.PartNo).KeyColumn("claimid").Table("wts_general_part").Element("partNo");
HasMany(x => x.Repairs).KeyColumn("claimid").Table("wts_Claim_Resolution").Element("resolutionDesc");
}
}
문제는 제가 수식이있는 조인 된 테이블을 가지고 있으며이 조인 된 테이블에 바인딩되어야합니다. 그래서 '(table3.id = table2.t3id table3.id = table2.t3id) max'(값 선택) '및 table1 t3id 너무 같은 별칭을 사용하지 않는 경우 .. 열이 모호합니다. 수식에 'where'가 없으면 모든 레코드를 취합니다 – buddy
매핑이 사용되는 곳에서 코드를 제공 할 수 있습니까? – eulerfx
가 게시물에 추가되었으므로 scm에서 온 것입니다. – buddy