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
When EF Core creates instances of these types, such as for the results of a query, it will first call the default parameterless constructor and then set each property to the value from the database. However, if EF Core finds a parameterized constructor with parameter names and types that match those of mapped properties, then it will instead call the parameterized constructor with values for those properties and will not set each property explicitly.
This suggests that parameterized constructors have priority over default parameterless in the case where both exist. My understanding from the comments on #10789 is the opposite:
@xKloc Starting with preview2, if there are both parameterized and empty constructors, then EF will choose the empty one. See #10852
Guys, 4 years from this. Common, is it so difficult to edit doc?
How to prioritize constructor for EF Core? I need some initialization logic in constructor and want it to be clear for users which one is for public and which is for EF Core
I tried something like this, but EF Core always choose constuctor with lower amount of parameters. But from doc it should use the 1st one.
Afterwards, we with team created really dirty hack to bypass this behaviour. We just renamed payload to body, to force EF Core not to use constructor for package consumers
From the page:
This suggests that parameterized constructors have priority over default parameterless in the case where both exist. My understanding from the comments on #10789 is the opposite:
I suggest the document wording be revised to make it clearer. It has taken me some digging today to clarify it.
My domain model has parameterised constructors that trigger domain events, so it is important EF uses the protected parameterless ones.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: