Add documentation for complex types - #5436
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a new EF Core “Complex types” modeling article and supporting sample code, and then wires that documentation into the site navigation and various “What’s new” pages for cross-linking.
Changes:
- Added a new
core/modeling/complex-types.mddocumentation page and linked it from the main TOC. - Added a new runnable sample project under
samples/core/Modeling/ComplexTypesto back the article’s snippets. - Added “TIP” cross-links from EF Core 8–11 “What’s new” pages (and owned types docs) to the new complex types documentation.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| samples/global.json | Moves samples to .NET 11 preview SDK for building/running updated samples. |
| samples/core/Samples.sln | Adds the new ComplexTypes sample project and updates solution configurations. |
| samples/core/Modeling/ComplexTypes/Program.cs | Sample runner demonstrating saving, sharing instances, change tracking, and querying. |
| samples/core/Modeling/ComplexTypes/Model.cs | Sample model types used across the documentation snippets. |
| samples/core/Modeling/ComplexTypes/DataAnnotations.cs | Demonstrates [ComplexType] data annotation usage for complex types. |
| samples/core/Modeling/ComplexTypes/ComplexTypesContext.cs | Demonstrates Fluent API configuration, JSON mapping, indexing, and discriminator usage. |
| samples/core/Modeling/ComplexTypes/ComplexTypes.csproj | New sample project targeting net11.0 with EF Core 11 preview dependencies. |
| entity-framework/toc.yml | Adds the new Complex types page to the Modeling section. |
| entity-framework/core/what-is-new/ef-core-8.0/whatsnew.md | Adds a TIP pointing readers to the comprehensive Complex types docs. |
| entity-framework/core/what-is-new/ef-core-9.0/whatsnew.md | Adds a TIP pointing readers to the comprehensive Complex types docs. |
| entity-framework/core/what-is-new/ef-core-10.0/whatsnew.md | Adds a TIP pointing readers to the comprehensive Complex types docs. |
| entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md | Adds a TIP pointing readers to the comprehensive Complex types docs. |
| entity-framework/core/modeling/owned-entities.md | Adds guidance pointing value-object scenarios toward complex types. |
| entity-framework/core/modeling/complex-types.md | New main documentation article for complex types (concepts, configuration, limitations, etc.). |
9ee3d07 to
c11d21c
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (2)
entity-framework/core/modeling/complex-types.md:35
- The comparison table says complex types have “Value semantics (properties are copied)”, but the very next row highlights that the same instance can be assigned to multiple properties. For reference-type complex types, “properties are copied” is misleading; it’s clearer to describe the semantics as “compared by value / reference identity is ignored”.
| Identity | Have a hidden key and identity | No identity; compared by value |
| Instance sharing | The same instance can't be referenced twice | The same instance can be assigned to multiple properties |
| Assignment semantics | Reference semantics | Value semantics (properties are copied) |
| .NET type | Reference types only | Reference _or_ value types |
entity-framework/core/modeling/complex-types.md:49
- Saying the assignment “simply copies the properties over” is misleading for the shown C# assignment (
customer.BillingAddress = customer.ShippingAddress;), which assigns the same instance for reference types. Consider rephrasing to focus on EF Core allowing the assignment (no identity conflict) and comparing by value, without implying automatic cloning.
Because complex types have value semantics, the same assignment simply copies the properties over, and works as expected. Similarly, comparing two complex values in a LINQ query compares their contents, whereas comparing two owned entities compares their identities.
</details>
c11d21c to
8d14627
Compare
8d14627 to
b3ff4ae
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (3)
entity-framework/core/modeling/complex-types.md:48
- “the same assignment simply copies the properties over” suggests EF/CLR performs a copy on assignment. For reference-type complex types, the assignment works, but it doesn’t necessarily copy; it can reference the same instance (and mutability later in this doc calls that out). Reword to avoid implying a copy occurs.
Because complex types have value semantics, the same assignment simply copies the properties over, and works as expected. Similarly, comparing two complex values in a LINQ query compares their contents, whereas comparing two owned entities compares their identities.
entity-framework/core/modeling/complex-types.md:35
- In this table row, “Value semantics (properties are copied)” is misleading for reference-type complex types: assigning one complex property to another assigns the same instance unless you create a new instance. Consider rephrasing to focus on comparison/change-tracking semantics rather than implying a CLR-level copy happens on assignment.
This issue also appears on line 48 of the same file.
| Identity | Have a hidden key and identity | No identity; compared by value |
| Instance sharing | The same instance can't be referenced twice | The same instance can be assigned to multiple properties |
| Assignment semantics | Reference semantics | Value semantics (properties are copied) |
| .NET type | Reference types only | Reference _or_ value types |
samples/core/Modeling/ComplexTypes/ComplexTypesContext.cs:9
- This project enables nullable reference types, and these DbSet auto-properties will typically produce CS8618 warnings (non-nullable property not initialized). Many other nullable-enabled sample contexts avoid this by using expression-bodied DbSet properties (=> Set()).
public DbSet<Customer> Customers { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<Distributor> Distributors { get; set; }
Fixes #4413