简体   繁体   中英

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.

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

在此输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM