przno
przno

Reputation: 3504

Entity framework DB first - private setter

For every table, EF generates a partial class, where all fields are publicly accessible, for example

public int ID { get; set; }

Is it possible to make the set private? I would then only allow the field to be changed calling my custom public method.

Upvotes: 3

Views: 783

Answers (1)

Dennis
Dennis

Reputation: 37770

Using designer, you can change visibility of setter from property grid. Just click on property, press F4, and select desired visibility:

enter image description here

But I recommend you to select protected instead of private, since there could be some difficulties (e.g. see this question).

Upvotes: 2

Related Questions