Adam
Adam

Reputation: 291

Entity Framework .. partial constructor

I intend to extend the constructors of some of the entities in my Entity Framework (4).

However how do I ensure that my constructor is run after the model has run its. i.e. I want to ensure that the the object holds the data from the database before I work on it in my constructor.

Upvotes: 6

Views: 5112

Answers (2)

Dave Cousineau
Dave Cousineau

Reputation: 13158

There is no generated constructor besides the default one; the objects are created via a factory method, and are simply initialized after construction.

You can write your own default constructor, and the generated code will call it before initializing all of the generated properties. If you write your own non-default constructor, you will also have to write your own default constructor, or else the designer file will not compile, since it assumes a default constructor exists.

Upvotes: 3

Pavel Minaev
Pavel Minaev

Reputation: 101565

Use constructor chaining.

Upvotes: 1

Related Questions