CodoMetis.TypeKit.EntityFrameworkCore
2.4.0-preview.3
Prefix Reserved
dotnet add package CodoMetis.TypeKit.EntityFrameworkCore --version 2.4.0-preview.3
NuGet\Install-Package CodoMetis.TypeKit.EntityFrameworkCore -Version 2.4.0-preview.3
<PackageReference Include="CodoMetis.TypeKit.EntityFrameworkCore" Version="2.4.0-preview.3" />
<PackageVersion Include="CodoMetis.TypeKit.EntityFrameworkCore" Version="2.4.0-preview.3" />
<PackageReference Include="CodoMetis.TypeKit.EntityFrameworkCore" />
paket add CodoMetis.TypeKit.EntityFrameworkCore --version 2.4.0-preview.3
#r "nuget: CodoMetis.TypeKit.EntityFrameworkCore, 2.4.0-preview.3"
#:package CodoMetis.TypeKit.EntityFrameworkCore@2.4.0-preview.3
#addin nuget:?package=CodoMetis.TypeKit.EntityFrameworkCore&version=2.4.0-preview.3&prerelease
#tool nuget:?package=CodoMetis.TypeKit.EntityFrameworkCore&version=2.4.0-preview.3&prerelease
CodoMetis.TypeKit.EntityFrameworkCore
Use CodoMetis.TypeKit value objects in EF Core
10 or 11 with one line of setup. Every value object is stored in a plain column of its underlying type,
with nothing to register per type, and .Value works in a LINQ query the way it does in memory.
dotnet add package CodoMetis.TypeKit.EntityFrameworkCore
This page is the reference for the package. For a walk through a whole model, read the EF Core guide.
Good to know
- It needs EF Core 10.0.12 or later on .NET 10, and EF Core 11.0.0 or later on .NET 11. A project
that references
Microsoft.EntityFrameworkCoreorMicrosoft.EntityFrameworkCore.Relationaldirectly at an earlier version fails to restore with NU1605 (a package downgrade). Raise the EF Core packages to that version or later. - On .NET 11, raise your database provider to 11 too. NuGet doesn't stop a provider of the 10 line
that is your only EF Core reference, such as
Microsoft.EntityFrameworkCore.Sqlite10. The project restores and builds with EF Core 11 under it, and the provider throwsMissingMethodExceptionorTypeLoadExceptionthe first time you use it. - The generators stay in your domain project. This package recognises a value object at run time
by the attribute the generators put on it. So the project that hosts the
DbContextneeds only this package and the base package. The domain project that declares the value objects referencesCodoMetis.TypeKit.Generators.
Setup
services.AddDbContext<ShopDb>(options =>
options.UseNpgsql(connectionString)
.UseTypeKit());
UseTypeKit() adds plugins to EF's type mapping, model conventions and query translation. It
replaces nothing. So it works alongside a provider or a library that replaces EF's converter
selector, and it doesn't matter whether you call it before or after UseNpgsql or UseSqlite. It
lives in the Microsoft.EntityFrameworkCore namespace, beside UseNpgsql, so it needs no using of
its own.
If your application builds EF's internal service provider itself, register the same services there:
var internalServices = new ServiceCollection()
.AddEntityFrameworkNpgsql()
.AddEntityFrameworkTypeKit()
.BuildServiceProvider();
Good to know
- It needs a relational provider. EF's in-memory provider has no relational type mapping, so
nothing is mapped there. A struct value object is stored as it is, a class value object fails the
model, and an integer key has no value generator (
SaveChangesthrowsNotSupportedException). For a database in memory in tests, use SQLite's (Data Source=:memory:).
What maps
public class Order
{
public required OrderId Id { get; init; } // key: uuid
public required CustomerId CustomerId { get; set; } // foreign key: uuid
public required ProductCode Code { get; set; } // text, keeps HasMaxLength(10)
public Discount? Discount { get; set; } // nullable integer
public required Amount Total { get; set; } // numeric
public required PlacedAt PlacedAt { get; set; } // timestamp with time zone on PostgreSQL
public List<Tag> Tags { get; set; } = []; // primitive collection: text[] on PostgreSQL, JSON elsewhere
}
Keys, foreign keys, nullable properties, primitive collections and query parameters all map as plain
columns of the underlying type. A facet you configure on the property, such as a maximum length or a
column type, is kept. (required is what the analyzer's CMTK0006 asks for. A value object nothing
assigns would be a default instance.)
A property can still name the converter explicitly:
modelBuilder.Entity<Order>().Property(o => o.Code).HasConversion<ValueObjectConverter<ProductCode, string>>();
Keys
A single-column key over an integer is generated on add, like a key of that integer type. That's EF's
own list: int, long, short, sbyte, uint, ulong and ushort, and not byte. So is the key
of an element of an owned collection (OwnsMany), which EF keys by the owner and the element's own
Id.
Whether a value then gets generated is up to the provider, as for a plain key. On PostgreSQL and SQL
Server it's an identity column, so switching an int key to a value object changes no schema there.
Where the provider has no identity for the type, the key isn't generated, just as a plain one isn't.
On PostgreSQL, for example, a ulong is a numeric(20,0), which can't be an identity.
At Add, a key that is generated gets the same temporary value a plain key of the underlying type
gets, also where the column is of another type, such as the decimal that holds a ulong. HiLo and a
value generator of your own still come first. There are three exceptions:
- A key over
charis yours to assign. It's never generated, on any provider, because none generates acharkey. PostgreSQL rejects an identity oncharacter(1), SQLite anAUTOINCREMENTonTEXT, and SQL Server has no identity fornvarchar(1). On SQL Server,Addused to give the value object one character of a GUID string, which was then stored. TypeKit stops that invented value, but it doesn't check that you set a meaningful one. A default key,'\0', is stored as it is, and a second such row fails on the primary key.ValueGeneratedOnAdd()or a value generator of your own on the property still applies. - On EF Core 10, a default key over
ulongcan still throw atAddwhere the column is adecimal(SQL Server, PostgreSQL), in two cases. One is a compiled model made withdotnet ef dbcontext optimize --nativeaot, which writes each column's mapping out as code and loses what gives the key a temporaryulong. The other is a key you configure withValueObjectConverteryourself. EF's temporary value for the column is then a negativedecimal, and converting it back throwsOverflowException. Otherwise the key gets a temporaryulong, as a plain one does. In those two cases, configureValueGeneratedNever()on the key and assign it. On EF Core 11 neither case throws: the key gets its temporaryulongin both. - On EF Core 11, SQL Server's HiLo isn't chosen for a key over
ulong. EF Core 11 leaves TypeKit one place to give that key its temporaryulong, a generator factory on the property, and SQL Server takes such a factory before HiLo.SaveChangesthen fails, because the column has no identity. Clear the factory on the key and HiLo is chosen again:Property(o => o.Id).Metadata.SetValueGeneratorFactory((Type?)null). On EF Core 10 you need nothing: HiLo comes first there.
A key over a Guid is yours to assign, Id = OrderId.New() (a version 7 Guid, which sorts by
creation time), and EF inserts it as given. To have EF generate it instead, configure
ValueGeneratedOnAdd() on the property. It's then generated as a plain Guid key is: a version 7
Guid on PostgreSQL, one that's sequential in SQL Server's order on SQL Server. EF then also treats
an entity whose key is already set, reached through a navigation, as an existing one.
The root of an inheritance hierarchy follows the same rules under TPH and TPT. Under TPC, as for an
int key, the key is generated only where the provider numbers the whole hierarchy from a sequence
(PostgreSQL, SQL Server), an abstract root's included. SQLite has no such sequence, so there you
assign it.
Name the value object itself in a key or an index: HasKey(o => o.Id) and HasIndex(o => o.Code),
not o.Id.Value. EF Core 11 reads HasKey(o => o.Id.Value) as a key inside a complex type, and would
store the value object as one, in a column Id_Value that TypeKit doesn't map. UseTypeKit() stops
the model there and names the property. On EF Core 10, EF rejects that path itself. In a query,
.Value still reads the column.
A configuration you write yourself always wins over these defaults.
SQLite: configure integer keys with UseAutoincrement()
modelBuilder.Entity<Invoice>().Property(i => i.Id).UseAutoincrement();
SQLite fills such a key in. But EF's SQLite provider makes a key AUTOINCREMENT only when the
property's CLR type is an integer, and a value object isn't one. A migration snapshot records the
column as an int, which is. So without this configuration the model never matches its snapshot:
- Every migration repeats an
AlterColumn, which is a table rebuild on SQLite. migrations has-pending-model-changesalways reports changes.Migrate()throws forPendingModelChangesWarning.
Configure each such key, as above. A model that also runs on another provider does this under
if (Database.IsSqlite()).
Model-wide conventions follow the property's type
EF applies ConfigureConventions by CLR type. So
configurationBuilder.Properties<decimal>().HavePrecision(18, 2) reaches decimal properties, and
not an Amount that wraps one. Configure the value object instead:
configurationBuilder.Properties<Amount>().HavePrecision(18, 2).
Closed sets
A closed set (IClosedSet<TSelf>) is stored as a text column of the member's name, and read back as
the member itself. That holds in a table, in a primitive collection of names (text[] on PostgreSQL,
a JSON array elsewhere) and in a JSON column alike, with nothing registered per set.
A name the set no longer has throws when it's read, rather than reading as null. An instance that
isn't a member throws when it's written. ClosedSetConverter<TSet> names the converter for an
explicit configuration.
Option and Result are not columns
EF can't map them, and building the model fails with an error that says so. Declare an optional value
as T? on the entity, and call ToOption() where your domain wants an Option.
Queries
db.Orders.Where(o => o.Id == id); // WHERE o."Id" = @id
db.Orders.Where(o => ids.Contains(o.Id)); // WHERE o."Id" = ANY (@ids)
db.Orders.Where(o => o.Code.Value.StartsWith("A")); // WHERE o."Code" LIKE 'A%'
db.Orders.Where(o => o.Total.GetValue() > 100m); // WHERE o."Total" > 100.0
db.Orders.Where(o => o.Discount.ValueOrNull() > 10); // WHERE o."Discount" > 10
db.Orders.Where(o => o.Tags.Contains(tag)); // WHERE @tag = ANY (o."Tags")
db.Orders.Where(o => o.Tags.Any(t => t.Value == "x")); // WHERE EXISTS (SELECT 1 FROM unnest(o."Tags") AS t(value) WHERE t.value::text = 'x')
db.Orders.OrderBy(o => o.PlacedAt);
The comments are the SQL EF Core 10 writes. EF Core 11 leaves out a cast that changes nothing, so
there the query over Tags ends in WHERE t.value = 'x'.
.Value, GetValue() and ValueOrNull() translate to the column itself. So the underlying type's own
operations work on it: StartsWith, arithmetic, comparisons. Use ValueOrNull() for an optional
value object, where .Value would first unwrap the Nullable.
A table's column is re-typed, not cast, so an index on it still serves the query. These are converted instead, which works everywhere and may add a cast:
- the element of a primitive collection (
o.Tags.Any(t => t.Value == "x")); - a property mapped into a JSON column;
- a parameter.
Good to know
.Valuetranslates only where the column holds the underlying value. That's where TypeKit's converter stores it: the oneUseTypeKit()applies, orValueObjectConverter<,>named inHasConversion. A property your application converts itself (HasConversion(c => "C:" + c.Value, ...), a converter type, a conversion inConfigureConventions) doesn't hold.Value. So a filter, a sort, a grouping or an aggregate that reads.Valuethere fails with EF's "could not be translated", rather than comparing against what the column really holds. Selecting.Valueas the query's last step still works,Distinctincluded: EF reads the value object through your converter and takes.Valuein memory. Comparing the value object itself (o.Code == code) goes through that converter and still works.Ordering in SQL follows the database's collation for the column. The generated comparison in memory is ordinal for a string, as it is for any string column.
A null passes no
<,<=,>or>=in the database. SQL leaves out a row whose column is NULL, as it does for anint?column. A value object that's a record class puts null first in memory, so therenull < rankis true. For a nullableRankrecord class,o.Rank < rankkeeps an order without a rank in a list, and leaves it out of the query. Writeo.Rank == null || o.Rank < rankto keep it in the query too. A struct value object answers the same both ways.Your own
CompareTo(TSelf)can't run in the database. A value object that declares one orders in memory by that method. The column orders by the underlying value, which could be the opposite of a descendingCompareTo. So these queries throw anInvalidOperationExceptionnaming the value object:- a comparison (
<,>,<=,>=,CompareTo); - an ordering (
OrderBy,ThenBy, their descending forms,Order); - the database's own orderings:
EF.Functions.GreatestandLeast, and a row-value comparison such as Npgsql'sEF.Functions.GreaterThan((o.Priority, o.Id), (priority, id)); MinorMax.
That holds when the value object is cast to
objectfirst, as inSelect(o => (object)o.Priority).Max(), and when the cast value reaches the ordering another way, through??, a member of a projection, a grouping's key, a join or a subquery'sFirst(), as inSelect(o => new { Key = (object)o.Priority }).OrderBy(a => a.Key): EF drops the cast, while memory still orders by yourCompareTo.Compare or order by
.Valuewhere the underlying value's order is what you mean (OrderBy(o => o.Priority.Value)), or order in memory after the query. Equality isn't ordering, and stays allowed. A query filter (HasQueryFilter, named or not) that does the same fails when the model is built, naming the entity type, since it applies to every query of that type.- a comparison (
A value object's arithmetic runs as the underlying type's. The operators TypeKit generates (Add, subtract and scale) work in a query.
o.Price * 2m > limitkeeps the rows memory keeps, ando.Tax / o.Pricereads adecimal. The database computes them, on SQLite, PostgreSQL and SQL Server alike.Your own operator can't run in the database. EF reads
o.Price + o.Taxas the database's own addition of the two columns and never calls your+. Whatever your operator does beyond that, such as rounding, would be skipped. So a query that uses an arithmetic or bitwise operator you wrote on a value object,&&and||included, throws anInvalidOperationExceptionnaming the value object. Compute it from.Valuewhere the underlying type's arithmetic is what you mean (o.Price.Value + o.Tax.Value), or do it in memory after the query. A query filter that uses one fails when the model is built. An operator over values you pass in, which EF computes before the query, stays allowed.Over a
byte,shortorchar, an operator throws as well, naming the value object. C# computes their arithmetic as anint's, and EF has no expression for theirs.Over a column your own converter stores, an operator isn't translated, as
.Valueisn't: the column doesn't hold the underlying value, so EF's "could not be translated" is the answer. As the query's last step, aSelectstill works: EF computes it in memory.One exception: a filter may order values your context holds, without a lambda, as in
HasQueryFilter(o => o.Priority == Limits.Max()). EF works that out in memory, by yourCompareTo. With a lambda, as inLimits.OrderByDescending(l => l).First(), EF orders those values in the database, so that filter fails too.
On SQL Server
A value object behaves on SQL Server as the type inside it does there. That isn't always how it behaves in memory:
- Text compares ignoring case. Under SQL Server's default collation,
o.Note == note,notes.Contains(o.Note)andStartsWithalso match text that differs in case or in trailing spaces.OrderBysorts ignoring case too. In memory, a value object over text equals only the same text, exactly. Where case matters, give the column a binary collation:UseCollation("Latin1_General_BIN2"). - Guids sort by their last group. SQL Server orders a
uniqueidentifierby its last six bytes first. SoOrderBy,<andMinover Guids come out in another order than in memory. - A
decimalwithout a precision is adecimal(18,2). It reads back with two decimal places:10mcomes back as10.00m, which is equal but prints10.00. More decimal places are rounded when the value is written. Configure the precision you need, on the property withHasPrecisionor for every such value object withconfigurationBuilder.Properties<Amount>().HavePrecision(18, 4). - A
TimeSpanmust be shorter than a day. It's stored astime. A longer one failsSaveChangesin a column. In a JSON column it's stored, but a query that reads it gets another value,01:02:00for1.02:00:00, without an error. Until EF Core 12, a constant of a day or more in a query is compared as its time of day, soTimeSpan.FromHours(30)is compared as06:00:00. Store a longer duration as a number instead, such as a value object over the seconds as along. EF.Functions.GreatestandLeastneed compatibility level 160. Configure it withUseSqlServer(connectionString, sql => sql.UseCompatibilityLevel(160)). Below it, EF refuses them. EF Core 11 assumes 160 already.- At compatibility level 170,
Containsover a list of value objects reads the list row by row. On SQL Server 2025,UseCompatibilityLevel(170)stores a list as SQL Server'sjsontype, and EF Core 11 writesJSON_CONTAINSforo.Tags.Contains(tag). For a list of value objects, TypeKit writes the query aso.Tags.Where(t => t == tag).Any()instead, so you get the rows memory gives you, for every type inside, and a search for a null included. Over a plainList<DateTime>orList<Guid>, EF'sJSON_CONTAINSfails with "Argument data type ... is invalid", andContains(null)finds no row. - A list of a nullable struct value object,
List<OrderId?>, can't useContainsat level 170. The query throws, naming the value object. Writeo.Tags.Where(t => t == tag).Any()yourself. Don't writeo.Tags.Any(t => t == tag): EF Core 11 turns it back intoJSON_CONTAINS. - A
DateTimecomes back without its kind.datetime2keeps every tick, and a UTC value reads back withKindUnspecified. It's still equal to the value you wrote.
The mapping is tested on SQLite, PostgreSQL and SQL Server. The SQL of each translation is pinned on
PostgreSQL. Every family of underlying types makes a round trip through a real PostgreSQL and a real
SQL Server, and every query and key shape of the test catalogue runs on the real SQL Server too:
SQL Server 2022, at EF's default compatibility level and at 160. Contains over a list of every type
inside also runs on SQL Server 2025 at level 170.
An Option for nothing found
Option<Order> order = await db.Orders.FirstOrNoneAsync(o => o.Id == id); // the database runs the condition and returns one row
Option<Order> earliest = db.Orders.OrderBy(o => o.PlacedAt).FirstOrNone(); // the same, synchronous
Result<Order, OrderFault> found = db.Orders.FirstOrError(o => o.Id == id, OrderFault.NotFound);
These ask the database for one row and let it run the condition:
FirstOrNoneAsync, and the base package'sFirstOrNoneandFirstOrErroron a query, read one row:WHERE ... LIMIT @p.FirstOrDefaultAsyncwould hand back adefaultvalue object when nothing is found (CMTK0009).SingleOrNoneAsyncandSingleOrNoneask for two rows, and throw for more than one.ElementAtOrNoneskips to its row:OFFSET @p.
Good to know
- The condition must be an expression. A lambda written at the call is one. A
Func<Order, bool>held in a variable, or a method group, bindsFirstOrNone,SingleOrNoneandFirstOrErrorto their overloads on a sequence. Then every row is read and the condition runs in memory, and the analyzer warns at the call (CMTK0009). Hold anExpression<Func<Order, bool>>instead.FirstOrNoneAsynctakes only an expression, so aFuncthere doesn't compile. LastOrNoneandLastOrErroron a query don't compile. A query has no last row until it's ordered. So order it the other way and take the first, or callAsEnumerable()to read every row on purpose.- Under Native AOT these throw "Query wasn't precompiled" (measured with EF Core 10.0.12). EF
runs only the queries it precompiled, and it precompiles a query where your application calls one
of EF's own operators, which these helpers aren't. Write
Where(...).Take(1).ToListAsync()at the call site instead, and take the first element of the list.
Reading back skips validation
var orders = await db.Orders.AsNoTracking().ToListAsync();
foreach (var order in orders.Where(o => o.Code.Revalidate().State == ResultState.Error))
log.StoredCodeNowRefused(order.Id);
EF reads a column back without validation, through IValueObjectMaterializer<,> rather than
Create. A rule you add to a value object later shouldn't make the rows written before it
unreadable. And the database holds what your application wrote, so it's trusted.
Input still goes through Create. Nothing in this package can be reached from a request, and calling
Materialize anywhere else gets reported by the analyzer (CMTK0004).
When you add a rule, Revalidate() finds the rows it rejects, as above.
Compiled models and Native AOT
dotnet ef dbcontext optimize --precompile-queries --nativeaot
EF Core runs under Native AOT only through a compiled model and precompiled queries, and it supports
that experimentally. UseTypeKit() works there. In the native binary:
- Value objects and closed sets map through the compiled model, a JSON column included.
.Valuetranslates in precompiled queries.- A value-object or closed-set parameter binds.
- A stored value reads back without the rules.
- A key over an integer is generated by the database.
The consumer smoke test runs exactly that. A compiled model without Native AOT works the same way.
This package adds no trim or AOT warning of its own. EF's DbContext constructors report theirs,
which EF's documentation covers.
Five EF limitations to know, measured with EF Core 10.0.12:
- A struct value object that wraps a reference type (
string,Uri) can't be a property in a compiled model. EF can't write its sentinel, sincedefault(ProductCode)converts tonull, anddbcontext optimizefails with "The type mapping for 'ProductCode' has not implemented code literal generation". Declare such a value object as asealed partial record. - A sealed entity class doesn't compile in EF 10's precompiled queries (CS0030 in the generated interceptors).
- Precompiled queries need the converter
UseTypeKit()composes. They cast a property's converter to the type it had at design time. The compiled model doesn't recreate that for aValueObjectConverter<,>or aClosedSetConverter<>named inHasConversion. - Precompiled queries compile the project they're in without the generators' bodies.
--precompile-queriesreads the generated members as declarations only. So a value object or a closed set declared in that project fails it (CS0534, CS0177 in the generated code). Declare them in another project, as a domain library usually is. - A collection of converted elements can't be read by a precompiled query. That's a
List<OrderId>or aList<OrderStatus>as much as aList<DayOfWeek>stored as text by EF's own converter. Precompilation fails withEncountered a constant of unsupported type 'ValueConverter`2'. An entity with any primitive collection, aList<string>too, fails to materialize in a precompiled query (aBadImageFormatExceptionfrom an accessor EF generates). A query compiled at run time, without Native AOT, handles both.
| Product | Versions 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. net11.0 is compatible. |
-
net10.0
- CodoMetis.TypeKit (>= 2.4.0-preview.3)
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.12)
-
net11.0
- CodoMetis.TypeKit (>= 2.4.0-preview.3)
- Microsoft.EntityFrameworkCore.Relational (>= 11.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.4.0-preview.3 | 0 | 12/3/2026 |
| 2.4.0-preview.2 | 62 | 11/30/2026 |
| 2.4.0-preview.1 | 62 | 11/30/2026 |
| 2.3.1 | 1,360 | 10/31/2026 |
| 2.3.0 | 413 | 10/29/2026 |
| 2.2.0 | 754 | 10/18/2026 |
| 2.1.0 | 1,293 | 10/15/2026 |
| 2.0.0 | 194 | 10/14/2026 |
| 1.5.1 | 142 | 10/11/2026 |
| 1.5.0 | 123 | 10/11/2026 |
| 1.0.0 | 152 | 9/28/2026 |
Added
- Generators: on .NET 11, a value object can wrap a C# 15 union or a closed class, and is written to JSON as what it wraps, byte for byte. A source-generated context, which Native AOT needs, lists the union or the closed class beside the value object (Unions and closed classes (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Generators/README.md#unions-and-closed-classes), #223 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/223)).
- Generators README: on .NET 11, "X" formats a value object over a double, float or Half as a hex float, as it does the underlying type, and Parse rejects one; a value object offers no TryParsePartial (Parsing and formatting (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Generators/README.md#parsing-and-formatting), #319 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/319)).
- Generators: on .NET 11, a value object can wrap Decimal32, Decimal64, Decimal128 or BFloat16, with the JSON, parsing, formatting, comparison and OpenAPI schema of the type it wraps. EF Core 11 maps none of the four, and rejects a value object over one as it rejects the type (Numbers (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/docs/value-objects.md#numbers), #212 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/212)).
- Testing: on .NET 11, ShouldBeCase<TCase>() checks which case a C# 15 union holds and hands it back, so result.ShouldBeError().ShouldBeCase<NotFound>() needs no switch. A failure names both cases and never their content. The package has a net11.0 asset for it, and its net10.0 asset is unchanged (CodoMetis.TypeKit.Testing (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Testing/README.md), #210 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/210)).
- Core and Analyzers: [UnionType] and [ClosedHierarchy] ask a type parameter for a C# 15 union or a closed class or record, as where can't, and CMTK0010 fails the build at any other type argument, a type that implements IUnion alone and a subtype of a closed class included; the compiler decides what each type is, so the check runs where a project compiles C# 15 (CMTK0010 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0010), #209 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/209)).
Changed
- Generators: the package now requires Metalama.Framework 2027.0.10-preview, the current Metalama 2027.0 preview, where 2.4.0-preview.2 required 2027.0.9-preview. A project that references Metalama.Framework itself moves with it (#381 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/381)).
- Generators: a union that declares a value-object marker fails with CMTK1005 naming the union, where it failed with CMTK1000 to CMTK1002 and a Metalama crash (LAMA0555, LAMA0041). A closed class with a marker (CMTK1022) or declared as a closed set (CMTK1014) is now named as closed (Build errors (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Generators/README.md#build-errors)).
- Analyzers: CMTK0008 now also warns at .NET 11's FullJoin whose key selectors unwrap two different value objects, orders.FullJoin(customers, o => o.Id.Value, c => c.Id.Value, …), as at the other joins. In a build that treats warnings as errors, that can report code that built before (CMTK0008 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0008), #273 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/273)).
- ASP.NET Core: the README says what ASP.NET Core 11 does with value objects: [Obsolete] on a value-object property is deprecated, except in an OpenAPI 3.0 document with components; a list or an array is named after its element; AddValidation() checks the body around a value object, and [StringLength] or [MaxLength] on a value-object property fails every request (Binding (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.AspNetCore/README.md#binding)).
- Core: the package has a net11.0 asset beside net10.0, with the same dependencies, for the one thing that differs there: reading the case a C# 15 union holds. A net11.0 project gets it with no change of its own.
- Analyzers: CMTK0005 now also warns where ImmutableArray<OrderId>.Builder.Count is set, builder.Count = count, which adds a default item for each one the count grows by; a constant zero, -- and -= aren't reported. In a build that treats warnings as errors, that can report code that built before (CMTK0005 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0005)).
- Analyzers: CMTK0005 now also warns at Array.Clear(ids) and ids.AsSpan().Clear() on an array or span of value objects, with a message of its own: clearing puts default back into every slot. A constant length of zero isn't reported. In a build that treats warnings as errors, that can report code that built before (CMTK0005 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0005)).
- Analyzers: CMTK0004 now also fails the build at Materialize called on a generic value object written by hand, Code<int>.Materialize(text), which skipped its rules unreported. It is an Error, so code that built before can fail: call Create there (CMTK0004 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0004), #353 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/353)).
- Analyzers: CMTK0006 now warns when a constructor sets a member only inside a lambda or a local function it doesn't call, Complete = () => Id = id, which runs later or never. In a build that treats warnings as errors, that can report code that built before (CMTK0006 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0006), #352 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/352)).
- Analyzers: CMTK0008 now also warns at a comparison whose arguments are named in another order, string.Equals(comparisonType: c, a: label.Value, b: title.Value). In a build that treats warnings as errors, that can report code that built before (CMTK0008 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0008), #355 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/355)).
- Analyzers: CMTK0014 now also warns at new FaultKind(), the same zero as new() and default. In a build that treats warnings as errors, that can report code that built before (CMTK0014 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0014), #354 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/354)).
Fixed
- ASP.NET Core: a merge-patch type that holds a patch of itself, Patch<NodePatch> inside NodePatch, crashed the process with a stack overflow while the OpenAPI document was made. It's described once below the patch, and {} where it repeats, as ASP.NET writes a recursive type it inlines (What the document says (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.AspNetCore/README.md#what-the-document-says), #365 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/365)).
- Analyzers: CMTK0003 no longer fails the build at await pending.TapAsync(log) on a Task<Option<T>> you hold, as it never did for a Task<Result<…>> (CMTK0003 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0003), #349 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/349)).
- Analyzers: CMTK0011's fix no longer changes what new Plugin() builds where a constructor's parameters are all optional. It adds public Plugin() : this(retries: 3) { }, and offers no fix beside a params array or two such constructors (CMTK0011 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Analyzers/README.md#cmtk0011), #350 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/350)).
- Generators: a protected internal nested value object gets its {TSelf}Extensions class, internal, so GetValue() and ValueOrNull() work on it. It had none (What is generated (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Generators/README.md#what-is-generated), #360 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/360)).
- Generators: a closed set builds with a member declared as an escaped keyword, @default, and names it default. The build failed with LAMA0041 (Handle every member (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/docs/closed-sets.md#handle-every-member), #361 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/361)).
- Generators: a closed-set member created with one new is no longer refused with CMTK1019 for a ) inside a raw, interpolated or UTF-8 string argument, new("""a)b""") (Rules for a closed set (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Generators/README.md#rules-for-a-closed-set), #362 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/362)).
- Generators: a value object that inherits Create from a base record in another project builds with an overload the generated call can't mean beside it, such as Create(int) over a string. It was refused with CMTK1011 (Write your own members (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Generators/README.md#write-your-own-members), #363 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/363)).
- EF Core: on EF Core 11 at compatibility level 170 (SQL Server 2025), o.Tags.Contains(tag) over a list of value objects answers the rows it answers in memory, for every type inside. EF writes JSON_CONTAINS there, which picked another path for a value object than for the type inside: over a value object wrapping a string, Contains(null) found no row. TypeKit now writes it as o.Tags.Where(t => t == tag).Any(), in queries and query filters. A list of a nullable struct value object, List<OrderId?>, is refused there, naming it (On SQL Server (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.EntityFrameworkCore/README.md#on-sql-server), #325 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/325)).
- Generators: a value object over a union with a string case has no Parse. It parsed every text as that case, so Parse("5") over union(int, string) gave the text "5", written as "5" where From(5) writes 5.
- Generators: From rejects a union that holds no case, its default, as it rejects a null. It was written to JSON as null, which the value object then refused to read.
- Base: on .NET 11, a value object writes and reads a number as its wrapped type does where a resolver sets number handling on the wrapped type's contract. The serializer's number converters apply the options' number handling themselves there, so a value object over a double wrote "0.25" where its contract said to write 0.25 (#334 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/334)).
- ASP.NET Core: on .NET 11, each case of a C# 15 union is described in the OpenAPI document, a value object as its underlying type and a closed set as the enum of its names. A case was {}, which accepts anything, unless another endpoint had made its component (What the document says (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.AspNetCore/README.md#what-the-document-says), #321 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/321)).
- JSON: under WhenWritingDefault, a record value object holding its wrapped type's default (Points.From(0)) was written where an int 0 is left out. Add ValueObjectJsonModifiers.WhenWritingDefault to your resolver and it's left out too (Leaving out a default (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/docs/json.md#leaving-out-a-default), #324 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/324)).
- Core, Testing: on .NET 11, a message that prints an error prints the case a C# 15 union holds, as it prints an enum error's member: Slug refused the input (SlugTooLong { Length = 13 }). from Parse, a JSON read and FromKnownGood, and is the error SlugTooLong { Length = 13 }. from ShouldBeSuccess() and ShouldBeError(expected). Each printed the union's type name, which says nothing about which rule failed. A union with a ToString() of its own prints that (A value object refused a value (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit/README.md#a-value-object-refused-a-value), #331 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/331)).
- Generators: a base record's explicit IEquatable<TBase> or arithmetic operator is found when the base is in another project. It was missed there: a HashSet of the base held two equal value objects, a public + was generated beside the base's, and CMTK1023 stayed silent (write your own members (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Generators/README.md#write-your-own-members), #356 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/356)).
- Generators: on .NET 11, a JSON read rejects a union that holds no case, as From does. A converter registered for the union could hand one back, and the value object then wrote null, which it refused to read (unions and closed classes (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Generators/README.md#unions-and-closed-classes), #357 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/357)).
- Base: text the underlying type's own parser answers with null is rejected: Parse and the type converter throw the FormatException, and TryParse answers false. They built a value object whose Value was null (when text is rejected (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Generators/README.md#when-text-is-rejected), #358 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/358)).
- Generators: TryParse answers false for a null string over every underlying type. Over one whose span parser reads empty input it answered true (when text is rejected (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.Generators/README.md#when-text-is-rejected), #359 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/359)).
- ASP.NET Core: [FaultStatus<LookupFault>(nameof(LookupFault.Gone), 410)] on an enum alias, Gone = Missing, sets the status of the member it shares a value with. The host refused to start, saying the name was no member (a status per endpoint (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.AspNetCore/README.md#a-status-per-endpoint), #367 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/367)).
- ASP.NET Core: a nullable value object over a type described by anyOf or oneOf, such as a C# 15 union, admits null in the document where the host inlines every schema. The schema refused the null the endpoint wrote (what the document says (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.AspNetCore/README.md#what-the-document-says), #368 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/368)).
- ASP.NET Core: a property with a converter of its own on a value object or a closed set is no longer described as the underlying type, which the converter doesn't write. It's left as ASP.NET writes any custom converter (what the document says (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.AspNetCore/README.md#what-the-document-says), #369 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/369)).
- ASP.NET Core: on .NET 11 with schemas inlined, fault and rule are described on the problem only. A response type declared beside it with a problem's property names and more got them too (a Result as a response (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.AspNetCore/README.md#a-result-as-a-response), #370 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/370)).
- EF Core: the key of an owned collection's element (OwnsMany) over an integer value object is generated on add, as an int key there is. Two elements added without an id had one key, and the second couldn't be tracked (keys (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.EntityFrameworkCore/README.md#keys), #348 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/348)).
- EF Core: an ordering by a value object with its own CompareTo, boxed and reached through LeftJoin, RightJoin or .NET 11's FullJoin, is refused as through Join. The database ordered it by the stored value (queries (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit.EntityFrameworkCore/README.md#queries), #366 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/366)).
- Base: the JSON refusal of an Option or a Result over a type nested in a generic type, Option<Scope<int>.Payload>, is the NotSupportedException again. Naming the type threw ArgumentOutOfRangeException. A refusal now names a nested type with its containing types, Scope<Int32>.Payload, and so does the message of a default Fault<A, B> (not wire types (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/v2.4.0-preview.3/src/CodoMetis.TypeKit/README.md#not-wire-types), #351 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/351)).
- Serilog: Destructure.WithTypeKit() no longer keeps a collectible assembly from unloading. It remembered every type it was asked about for the life of the process (#364 (https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/issues/364)).
Full changelog: https://github.com/CaffeinatedCoder/CodoMetis.TypeKit/blob/main/CHANGELOG.md