엔티티 "B"및 "C"에 대한 링크를 갖는 동안 "A"엔티티를 반환해야하는 쿼리가 있으며이 두 링크에는 "왼쪽 외부 조인"연산자 하나의 링크 또는 다른 링크에서 "A"엔티티를받을 수 있습니다.왼쪽 외부 조인을 사용하여 두 개의 링크 기준과 일치하는 엔티티를 반환하는 쿼리
실행 후 2 개의 링크 기준에 공통된 레코드 하나만 반환합니다. 엔티티 "B"에 대한 링크를 제거하면 링크 기준과 일치하는 예상 레코드를 얻습니다. 엔티티 "B"에 대한 링크가있는 동안 엔티티 "C"에 대한 링크를 제거하면 동일하게됩니다.
그래서 내 쿼리가 하나의 링크에서만 작동한다고 가정하지만 두 개의 링크가 있고 그 이유를 이해하지 못하는 경우 예상대로 작동하지 않습니다.
실제로 나는이 다음을했습니다.
이_____________
| A |
-------------
| a_id |
| 1 | - entity with this id is the only record in the results
| 2 | - entity with this id should appear in the results, but it is not
| 3 | - entity with this id should appear in the results, but it is not
_________________________________
| B |
---------------------------------
| b_one_id | b_two_id |
| 1 | 1 | - matches link criteria with alias "connectionB"
| 2 | 1 | - matches link criteria with alias "connectionB"
| 1 | 444 | - doesn't match link criteria, should not appear
_________________________________
| C |
---------------------------------
| c_one_id | c_two_id |
| 1 | 2 | - matches link criteria with alias "connectionC"
| 3 | 2 | - matches link criteria with alias "connectionC"
| 1 | 555 | - doesn't match link criteria, should not appear
내 쿼리 식 : 쿼리 식은 XML 쿼리를 가져 오기 다음으로 변환됩니다
QueryExpression query = new QueryExpression
{
EntityName = A.EntityLogicalName,
ColumnSet = new ColumnSet
{
AllColumns = false,
Columns =
{
"a_id",
"a_name"
}
}
};
query.Distinct = true;
query.AddLink(B.EntityLogicalName, "a_id", "b_one_id", JoinOperator.LeftOuter);
query.LinkEntities[0].EntityAlias = "connectionB";
query.LinkEntities[0].LinkCriteria.AddCondition("b_two_id", ConditionOperator.Equal, 1);
query.AddLink(C.EntityLogicalName, "a_id", "c_one_id", JoinOperator.LeftOuter);
query.LinkEntities[0].EntityAlias = "connectionC";
query.LinkEntities[0].LinkCriteria.AddCondition("c_two_id", ConditionOperator.Equal, 2);
// doesn't work as expected
query.Criteria.AddFilter(LogicalOperator.Or);
query.Criteria.Filters[0].AddCondition("connectionB", "b_one_id", ConditionOperator.NotNull);
query.Criteria.Filters[0].AddCondition("connectionC", "c_one_id", ConditionOperator.NotNull);
// doesn't work as expected either
query.Criteria.AddCondition("a_id", ConditionOperator.NotNull);
가 :
<fetch distinct="true" no-lock="false" mapping="logical">
<entity name="A">
<attribute name="a_id" />
<attribute name="a_name" />
<filter type="and">
<filter type="or">
<!-- doesn't work as expected -->
<condition attribute="b_one_id" operator="not-null" entityname="connectionB" />
<condition attribute="c_one_id" operator="not-null" entityname="connectionC" />
<!-- doesn't work as expected either -->
<condition attribute="a_id" operator="not-null" entityname="A" />
</filter>
</filter>
<link-entity name="B" to="a_id" from="b_one_id" link-type="outer" alias="connectionB">
<filter type="and">
<condition attribute="b_two_id" operator="eq" value="1" />
</filter>
</link-entity>
<link-entity name="C" to="a_id" from="c_one_id" link-type="outer" alias="connectionC">
<filter type="and">
<condition attribute="c_two_id" operator="eq" value="2" />
</filter>
</link-entity>
</entity>
</fetch>
그냥 시도하고 저를 위해 잘 작동합니다 - 3 개의 행이 있습니다. 어떤 필터없이 실행하고 당신에 대해 실행중인 데이터가 올바른지 (필터없이 6 행 : 4 행, 어디에 a_id = 1, 1 어디에 a_id = 2, 1 어디에 a_id = 3) 볼 수 있습니까? – MarioZG
안녕하세요, 2011 년 또는 2011 년이 crm입니까? 롤업? 이것이 crm 2011 인 경우 'outer join'은 다음과 같이 작동합니다. relasionship을 'outer'와 연결하면 조건에 맞지 않더라도'ALL records'를 검색하게됩니다. – Sxntk