Skip to content
This repository was archived by the owner on Jun 16, 2024. It is now read-only.

Correctly translating FetchXml with multiple filter nodes#507

Open
BetimBeja wants to merge 2 commits intojordimontana82:masterfrom
BetimBeja:multi-filter
Open

Correctly translating FetchXml with multiple filter nodes#507
BetimBeja wants to merge 2 commits intojordimontana82:masterfrom
BetimBeja:multi-filter

Conversation

@BetimBeja
Copy link
Contributor

Hello Jordi,
this fixes Bug #506.
Betim.

@jordimontana82
Copy link
Owner

recheck

TarogStar pushed a commit to TarogStar/fake-xrm-easy that referenced this pull request Nov 11, 2025
…s and left outer joins

This commit addresses critical FetchXML and query translation issues identified
from upstream repository analysis, significantly improving query compatibility
with real Dataverse behavior.

**Fix jordimontana82#1: FetchXML Multiple Filter Elements** (Resolves jordimontana82#507)

**Problem:**
- FetchXML allowed multiple <filter> elements at the same level
- Framework only processed the FIRST filter, ignoring all others
- This affected both entity-level and link-entity filters

**Solution:**
- Modified XmlExtensionsForFetchXml.cs ToCriteria() method (lines 217-241)
- Now collects ALL filter elements and combines with AND logic
- Modified ToLinkEntity() method (lines 302-321) for link-entity filters
- Matches real Dataverse behavior where multiple filters are AND'ed

**Files Changed:**
- FakeXrmEasy.Shared/Extensions/XmlExtensionsForFetchXml.cs

**Impact:**
- HIGH - FetchXML queries with multiple filters now work correctly
- Enables complex filtering scenarios previously impossible
- 100% backward compatible (single filter still works)

---

**Fix jordimontana82#2: Nested Left Outer Join Support** (Resolves jordimontana82#503)

**Problem:**
- Left outer joins with nested link-entities failed
- Nested entities were not included in the inner query
- Resulted in null reference errors or missing data
- Issue jordimontana82#191 documented this specific problem

**Solution:**
- Modified XrmFakedContext.Queries.cs TranslateLinkedEntityToLinq() (lines 333-355)
- For LeftOuter joins, nested LinkEntities now added to inner QueryExpression
- Skip redundant recursive processing for LeftOuter joins (lines 402-420)
- Ensures nested joins processed BEFORE outer join executes

**Files Changed:**
- FakeXrmEasy.Shared/XrmFakedContext.Queries.cs

**Impact:**
- HIGH - Nested left outer joins now work correctly
- Critical for complex reporting queries
- Fixes long-standing issue from upstream repository

---

**Test Coverage:**

Created comprehensive test suites:

1. **MultipleFiltersTests.cs** (9 tests):
   - Single filter (backward compatibility)
   - Two filters combined with AND
   - Three filters combined with AND
   - Multiple filters with OR type
   - Link-entity multiple filters
   - Empty filters
   - Nested filters within multiple top filters
   - QueryExpression equivalence verification

2. **LeftOuterJoinTests.cs** (8 tests):
   - Basic left outer join with no match
   - Nested left outer joins (2-4 levels deep)
   - FetchXML left outer joins
   - Filtered left outer joins
   - Multiple left outer joins at same level
   - Mixed inner and left outer joins
   - Deep nested left outer joins

**Total:** 17 new tests, all covering edge cases and real-world scenarios

---

**Upstream Issues Resolved:**
- jordimontana82#507 - FetchXML with multiple filter nodes
- jordimontana82#503 - Left outer join fixes
- jordimontana82#191 - Nested left outer joins

**Compatibility:**
- All changes are backward compatible
- Existing queries continue to work unchanged
- New functionality only activates when using multiple filters or nested joins

This represents a major improvement in query engine reliability and Dataverse compatibility.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants