Adding entities

At its simplest, creating a new instance of an entity is like creating a new instance of any .NET object: You simply call a constructor.

There’s nothing special about creating an entity instance. You’ve been doing it all along  by calling its constructor:

Image

The default code generation strategy for the Designer creates a factory method that accepts all required (not-nullable) properties as parameters. Of course, you create a method like this yourself if you’re using the Code First workflow:

Image

The context doesn’t watch entity creation, ...

Get Fluent Entity Framework now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.