dotnet / dotnet/EntityFramework.Docs
How does EF select a ctor for an entity with multiple ctors?
- Dominant language
- Mermaid
- Stars
- 1.7k
- Forks
- 2k
- Avg merge
- 7d 23h
- Merged PRs (30d)
- 16
Description
When an entity has multiple constructors, EF chooses one according to some undocumented logic.
Suppose an entity has a mix of:
- public parameterless constructor, and
- one or more parameterised constructors,
- of which some are private, protected, public, etc.
...then which constructor will EF choose?
The doc page only states this:
> Currently, all constructor binding is by convention. Configuration of specific constructors to use is planned for a future release.
*But the CURRENT selection logic is not described.*
I understand that in a [future release](https://github.com/dotnet/efcore/issues/10789) we will be able to specify which ctor to use, but until then, please document the current selection logic, because getting this to work in a large domain is extremely tedious trial-and-error.
---
#### Document Details
⚠ *Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.*
* ID: ecc7aedf-6301-7ec7-4f65-81749b1f54c8
* Version Independent ID: d0774ffa-c841-e6df-72de-d7f53c0d6f6f
* Content: [Entity types with constructors - EF Core](https://learn.microsoft.com/en-us/ef/core/modeling/constructors)
* Content Source: [entity-framework/core/modeling/constructors.md](https://github.com/dotnet/EntityFramework.Docs/blob/main/entity-framework/core/modeling/constructors.md)
* Product: **entity-framework**
* Technology: **entity-framework-core**
* GitHub Login: @ajcvickers
* Microsoft Alias: **avickers**
Contributor guide
Assessment
This issue has not been assessed yet.