Hide some entities and/or attributes

Problem

Sometimes we need to hide certain entities and/or attributes from data model (for example for security reasons). There are several ways to limit the quantity of entities and attributes shown in Data Model, and here we explain how to implement it.

Solution #0: Modify your model using Data Model Editor (DME)

In case your model is stored in some XML file you can just open it in DME and turn off Use in result and Use in conditions options for the entities and/or attributes you would like to hide. Here are the instructions:

  • Run DME
  • Open your model's XML file
  • Go to "Entities" tab
  • Select entity or attribute your would like to hide in the "Entities" tree view
  • Uncheck Use in result and Use in conditions checkboxes for selected item in the right panel

Solution #1: RunThoughEntity function

Here is an article which describes how to navigate through all entities in your model. To hide an entity from your model after loading it you just need to set UseInResult and UseInConditions properties for corresponding Entity object to false.

Add the following code to the RunThroughEntity function for the entities you would like to hide (we guess here that that is the entity named “User”):

If (entity.Name == “User”) {
  entity.UseInResult = false;
  entity.UseInConditions = false;
}

Solution #2: Scan method in Entity class (Version 3.8.0 and later)

Scan method in Entity class works exactly as RunThroughEntity function. You can call that method for root entity of your model and pass a delegate which will be called for each sub-entity.

So you model loading code will be equal to the following:

model.LoadFromDBContext(YourDbContextObject); //here we can use any other way of model loading of course

model.EntityRoot.Scan(entity => {
  if (entity.Name == "User") {
  entity.UseInConditions = false;
  entity.UseInResult = false;
  } 
}, null, false);

Solution #3: Eq.. attributes for DbContext classes

If you load data model right from DbContext, you can just add EqEntity and EqEntityAttr attributes in from of important class and property definitions. Here is an example:

  [EqEntity(UseInResult = false, UseInConditions=false)]
  public class Customer {

  [EqEntityAttr(UseInResult = false, UseInConditions=false)]
  public string Id { get; set; }
  
  . . . . . .