bcquality/microsoft/knowledge/performance/use-isempty-for-existence-checks.md
Jesper Schulz-Wedde 0540c7bf6e Reframe seed-article banners as community contribution invitations
The 35 articles still in their seed form previously carried a banner
reading "Seed article. ... Domain stewards should expand, restructure,
and refine as needed." For a community preview, that phrasing reads as
"TODO left in production" to first-time visitors.

Replace all three banner variants (performance-seeded, security-seeded,
community-ported) with a single positive invitation:

> Contributions welcome — open a PR to refine or extend this article.

Content and structure of the articles are unchanged; only the leading
quote block differs. Articles that had their banner fully stripped in
the earlier triage pass (the showcase-grade ten) are unaffected.
2026-04-23 17:31:36 +02:00

1 KiB

bc-version domain keywords technologies countries application-area
all
performance
isempty
count
findfirst
existence
al
w1
all

Use IsEmpty for existence checks

Contributions welcome — open a PR to refine or extend this article.

Description

IsEmpty is the cheapest way to answer whether at least one row matches the current filters. It short-circuits at the first match and never hydrates a record. Count() scans and counts the entire set; FindFirst fetches a full row just to be discarded.

Best Practice

Use if not Rec.IsEmpty() then ... for existence checks. Reserve Count for cases where the exact number of rows is needed, and FindFirst for cases where you actually want the row's field values.

See sample: use-isempty-for-existence-checks.good.al.

Anti Pattern

if Rec.Count() > 0 iterates the whole set just to answer a yes/no question. if Rec.FindFirst() then loads an entire row of data the caller never reads.

See sample: use-isempty-for-existence-checks.bad.al.