Soenneker.Cosmos.Linq 4.0.5

Prefix Reserved
dotnet add package Soenneker.Cosmos.Linq --version 4.0.5
                    
NuGet\Install-Package Soenneker.Cosmos.Linq -Version 4.0.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Soenneker.Cosmos.Linq" Version="4.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Cosmos.Linq" Version="4.0.5" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Cosmos.Linq" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.Cosmos.Linq --version 4.0.5
                    
#r "nuget: Soenneker.Cosmos.Linq, 4.0.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Soenneker.Cosmos.Linq@4.0.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.Cosmos.Linq&version=4.0.5
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Cosmos.Linq&version=4.0.5
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

Soenneker.Cosmos.Linq

Treat missing Cosmos DB properties as null in LINQ queries.

Install

dotnet add package Soenneker.Cosmos.Linq

Usage

Call WithNullSemantics() after adding filters and before executing the query:

using Microsoft.Azure.Cosmos.Linq;
using Soenneker.Cosmos.Linq;

var query = container.GetItemLinqQueryable<MyDocument>()
    .Where(d => d.Name == null)
    .WithNullSemantics();

using var iterator = query.ToFeedIterator();

What gets rewritten

Cosmos treats a missing property differently from an explicit JSON null. WithNullSemantics() rewrites your filters so both count as null:

Your filter Rewritten filter
d.Name == null !d.Name.IsDefined() \|\| d.Name.IsNull()
d.Name != null d.Name.IsDefined() && !d.Name.IsNull()
d.ReleasedAt.HasValue d.ReleasedAt.IsDefined() && !d.ReleasedAt.IsNull()
d.Source == null !d.Source.IsDefined() \|\| d.Source.IsNull()

IsDefined() checks whether the JSON property exists; IsNull() checks whether its value is JSON null. The Cosmos SDK translates these into IS_DEFINED(...) and IS_NULL(...) in SQL. Equality matches missing or null properties; inequality and HasValue require a present, non-null value.

Works with nullable value types, nested properties, and collection predicates. Types generated with [EnumValue] or [EnumValue<T>] work automatically—no registration needed.

When to call it

The extension rewrites the expression that exists when you call it. It returns a query with those changes; filters added afterward are not automatically rewritten.

var query = container.GetItemLinqQueryable<MyDocument>();
query = query.Where(d => d.Name == null);
query = query.Where(d => d.Source != null);

// Rewrite after composing filters, immediately before execution.
query = query.WithNullSemantics();
using var iterator = query.ToFeedIterator();

If you add more filters later, call it again before execution. Repeated calls do not duplicate the checks. In a repository, apply it inside the methods that execute queries, before ToFeedIterator(), ToQueryDefinition(), or CountAsync(). Calling it only when creating the initial query will miss filters added by callers.

Reusable predicates

Expression<Func<MyDocument, bool>> predicate = d => d.Name == null;
var query = container.GetItemLinqQueryable<MyDocument>()
    .Where(predicate.WithNullSemantics());

Other custom types

For other classes that overload == / !=, register the type at startup only if comparison with null means reference null:

CosmosNullSemantics.RegisterNullComparableType<MyCustomValue>();

Keep in mind

  • Use with native Cosmos SDK queries. Rewritten predicates are for Cosmos, not in-memory execution.
  • Checks against literal null and nullable .HasValue are supported. Captured variables and method results are left alone.
  • Explicit IsNull() and IsDefined() checks keep their original meaning.
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Soenneker.Cosmos.Linq:

Package Downloads
Soenneker.Cosmos.Repository

A data persistence abstraction layer for Cosmos DB

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.5 197 9/15/2026