Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F# immutable Records do not work #34357

Open
isaacabraham opened this issue Aug 4, 2024 · 2 comments
Open

F# immutable Records do not work #34357

isaacabraham opened this issue Aug 4, 2024 · 2 comments

Comments

@isaacabraham
Copy link

The following record does not work in EF Core:

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 [<CLIMutable>] 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.

@roji
Copy link
Member

roji commented Aug 5, 2024

Working with immutable types in EF is currently limited, since change tracking and updating rely on mutability (see #11457, this is regardless of F# or C#). Putting the above in the backlog to understand the F#-specific construction situation though.

@roji roji added this to the Backlog milestone Aug 5, 2024
@isaacabraham
Copy link
Author

Hi @roji - understood.

Good news is that I think most F# people using EF would probably use it in a "disconnected" mode - without change tracking. For that mode, you don't really care about the immutable nature (in the same way that many other things like Json deserialization, Dapper etc. don't need it). I think simply being able to construct records would be a big win in and of itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants