Build with an Azure free account. Get USD200 credit for 30 days and 12 months of free services.

Start free today

Modern Entity Framework: A Tour of EF Core 5.0 pt 1

Play Modern Entity Framework: A Tour of EF Core 5.0 pt 1

The Discussion

  • User profile image
    Aviad

    Regarding private constructors -
    1. How does EF Core know that the private constructor is used to initialize the _id field?
    2. What happens if we omit the id field from the private constructor?

    Thanks

  • User profile image
    Jeremy​Likness
    @Aviad:

    By convention; the `int id` parameter is matched to the `_id` field. If you omit the id field from the private constructor then EF Core will set the field directly. This is totally reasonable, but you’ll have to suppress compiler warnings that the field is never set.

Add Your 2 Cents