c# - ReadOnly Property that Entity Framework can set -


very basic, yet google-fu failing me.

i have domain object, user, want active property read on. yet, property needs set via ef(6) when loaded database.

table:

create table users (     id int not null primary key clustered,     active bit not null default 1     -- other stuff ); 

class:

public class user {     public int id { get; set; }     public bool active { get; set; }    // should ro      public void activate() {         active = true;         this.addchangelog(changetype.activation, "activated");     }      public void deactivate() {         active = false;         this.addchangelog(changetype.activation, "deactivated");     }      // changelogging, etc. } 

developers should not change active directly, instead should use activate() , deactivate() methods. yet, ef6 needs set active directly can instantiate object.

architecture (if matters):

  • user class exists in domain project
  • ef6 class configuration done via data project
  • ef6 uses fluent api configuration (keeps orm stuff out of domain project)
  • ef6 not use dtos configures domain classes directly

question

how can enforce (or @ least warn) devs not set user.active? @ least, can offer compile-time warning (akin [obsolete]) setter notice?

thanks,

you can use friend assemblies solve problem , make public project want , make private other projects.

[assembly:internalsvisibleto("cs_friend_assemblies_2")] 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -