Skip to content

Decide on which constructor to call by convention #10852

@ajcvickers

Description

@ajcvickers

EF may be able to call several of the constructors defined on an entity type. By convention, we should always choose the one with the most number of services that can map--similar to D.I. However, when mapping scalar properties, we could:

  • Call the parameterless constructor (or the constructor with only services) if it is available. This would avoid any breaking change because this is the kind of constructor EF has always called.
  • Call the constructor with the most scalar properties that match. The reasoning for this is that if a constructor that matches has been defined, then it could very well be intended that we call it. However, it may do extra validation or other things that are not needed/slow/harmful if called by EF

Note that if only one constructor is defined, then EF will use it--this is just about the case when multiple are defined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions