JasperFx / marten

.NET Transactional Document DB and Event Store on PostgreSQL
https://martendb.io
MIT License
2.82k stars 445 forks source link

Linq `Where()` condition no longer filters correctly after Marten 7 upgrade #3035

Closed lofbacke closed 7 months ago

lofbacke commented 7 months ago

This (admittedly convoluted) Where() condition in one of my Marten queries behaves differently after the upgrade:

public static Task<IReadOnlyList<TrackWarrantDetails>> GetTrackWarrantsForTerritory(
    this IQuerySession session,
    Guid territoryId,
    string? currentShiftId) =>
        session.Query<TrackWarrantDetails>()
            .Where(twd => twd.TerritoryId == territoryId &&
                (twd.IsActive || (currentShiftId != null && (
                twd.IssuedDuringShiftId == currentShiftId ||
                twd.AuthorizedDuringShiftId == currentShiftId ||
                twd.VoidedDuringShiftId == currentShiftId ||
                twd.LimitsReportedClearDuringShiftId == currentShiftId))))
            .ToListAsync();

Basically, we always want to filter the documents by TerritoryId. And if there is no currentShiftId, we only want the documents where IsActive is set to true. Otherwise, we want all active documents and documents where any one of several properties match the currentShiftId.

Prior to the update, this behaved as expected. However, after the update, the query returns all documents with a matching TerritoryId if currentShiftId is null, even if they are not marked as active. If a currentShiftId is provided, the query returns the expected results.

jeremydmiller commented 7 months ago

Fixed locally.