에서 쿼리 내가 함께 비교적 간단한 F#
쿼리 식을 조인 :leftOuterJoin와`.DefaultIfEmpty()`F 번호
let mdrQuery =
query {
for header in db.CustomerDetails do
leftOuterJoin row in db.MDR_0916
on (header.PID = row.PID) into result
select (result, header)
}
이 모든 header
및 result
를 반환하지만 header
에 대한 그 row
에 일치하지 않은, result
은 빈 시퀀스이며 쿼리 결과가 사용자 지정 유형에 전달되면 row
의 필드와 연결된 생성자가 정의되지 않은 오류가 발생합니다. 이는 row
에 일치가없는 header
인 경우 null
시퀀스가 반환된다는 의미입니다. 예 :
mdrQuery |> Seq.head;;
val it :
seq<dbSchema.ServiceTypes.MDR_0916> * dbSchema.ServiceTypes.CustomerDetails
= (seq [null], CustomerDetails {ACCOUNTMANAGER = null;
ACCOUNTSTATUS = "XC";
ADDRESSLINE1 = null;
ADDRESSLINE2 = null;
ADDRESSLINE3 = null;
ADDRESSLINE4 = "123 PIG ROAD"...
나는이 때문에 the leftOuterJoin
documentation here의 주위에 방법이 있다고 생각한다. 내가 내 쿼리에 대한 템플릿으로 그 예를 사용하려고 할 때, :
error FS0039: The field, constructor or member 'DefaultIfEmpty' is not defined
와
let mdrQuery =
query {
for header in db.CustomerDetails do
leftOuterJoin row in db.MDR_0916
on (header.PID = row.PID) into result
for row in result.DefaultIfEmpty() do
select (result, header)
}
.DefaultIfEmpty()
조각 오류 부족이 나는이 일어날 가입 할 수있는 방법과result
의 일치하지 않는 행을 None
(또는 다른 null SQL null 값)으로 채워 모든 쿼리를 내 레코드 유형으로 전달할 수 있도록 모든 행을 선택 하시겠습니까?
이상적으로, 일치하지 않는 행의 출력은 (아래 손으로 만든 절단 결과)
mdrQuery |> Seq.head;;
val it :
seq<dbSchema.ServiceTypes.MDR_0916> * dbSchema.ServiceTypes.CustomerDetails
= (MDR_0916 {AIMExp = null;
AP = null;
APComp = null;
APEng = null;
APFine = null;
APForl = null;...},
CustomerDetails {ACCOUNTMANAGER = null;
ACCOUNTSTATUS = "XC";
ADDRESSLINE1 = null;
ADDRESSLINE2 = null;
ADDRESSLINE3 = null;
ADDRESSLINE4 = "123 PIG ROAD"...
편집 같을 것이다 :This question/answer 내 유사하지만 ToOption result
을 포함하여 단순히 Some (seq [null])
출력한다.
대화 형 출력에서 'result'는 빈 시퀀스가 아니라 하나의 요소 시퀀스이며 그 요소는 'null'입니다. –
설명해 주셔서 감사합니다. – Steven
'DefaultIfEmpty'는 확장 메소드이므로'System.Linq'을 열어야합니다. – kvb