Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 322
przno Avatar asked Jun 05 '26 02:06

przno


1 Answers

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).

like image 195
Dennis Avatar answered Jun 07 '26 23:06

Dennis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!