dotnet / dotnet/efcore

F# immutable Records do not work

Open
#34,357 2 comments 0 reactions 0 assignees View on GitHub
area-F# customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

The following record does not work in EF Core:

```fsharp
type Todo = { Id: Guid; Title: string }
```

```
System.InvalidOperationException: No suitable constructor was found for entity type 'Todo'. The following constructors had parameters that could not be bound to properties of the entity type:
Cannot bind 'id', 'title' in 'Todo(Guid id, string title)'
Note that only mapped properties can be bound to constructor parameters. Navigations to related entities, including references to owned types, cannot be bound.
```

If you put the `[]` attribute on (which compiles the record with mutable properties and a default ctor) then it works. However, this is non-obvious and normal records should "just work" with EF.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.