You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not all data models work well with value equality. For example, Entity Framework Core depends on reference equality to ensure that it uses only one instance of an entity type for what is conceptually one entity. For this reason, record types aren't appropriate for use as entity types in Entity Framework Core.
There is no mention of this on the page Entity Types - EF Core or any other page in the EF Core documentation that I could find.
Please expand the EF core documentation to clearify the use of record types.
Please also include an explanation for why the default value equality of record types is actually a problem for EF Core. (If EF Core depends on reference equality (like documented above), then why doesn't EF Core just always use reference equality and ignore the equality implementation of the entity type?
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
ID: 6ffdc279-736f-92e4-6de3-cce42342cd6b
Version Independent ID: d3d4904a-f60d-a0a2-b634-cb12671fa7a2
For one thing, many people come to records in search of a quick-and-easy immutable type (and indeed, minimal record syntax with a primary constructor does produce an immutable type). Immutable types don't work well with EF regardless of records (dotnet/efcore#11457).
For another, records are very much about defining the equailty behavior of the type to be value equality. EF can indeed ignore that and use reference equality, but that's once again not what many users expect - after all, they've chosen to user records for a reason ("I've chosen value semantics, why does EF override that?").
All that isn't to say that it's impossible to use records with EF, just that it's usually not what users want. I agree the documentation on this can be improved though.
@PingvinB Please note that I created this issue explicitly for the Entity Types - EF Core page and also mentioned "entity" in the issue title. Also, EF Core 8 was not released when I created this issue, so "Complex Types" did not exist yet.
The section you linked explicitly mentions using C# record types as a "Complex type", not as an entity!
The page https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/types/records mentions this:
There is no mention of this on the page Entity Types - EF Core or any other page in the EF Core documentation that I could find.
Please expand the EF core documentation to clearify the use of record types.
Please also include an explanation for why the default value equality of record types is actually a problem for EF Core. (If EF Core depends on reference equality (like documented above), then why doesn't EF Core just always use reference equality and ignore the equality implementation of the entity type?
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: