Up Refine in the EDM Designer

Change member visibility

Last modified on August 20, 2013 19:11

You can change visibility of entity classes and properties in the EDM Designer but special rules apply for models used in Silverlight.


Class and property visibility

The generated Entity Data Model (EDM) classes and their members are Public by default.

That isn't always a good idea. Some classes shouldn't be changed or constructed. Some properties should be read-only.

You can change the visibility of a class or property in the EDM Designer. Locate the object in the Model Browser, open its Properties window, and find the "Code Generation" category. Entity and property options differ:

Entity visibility
EdmDesignerPropertiesEntityVisibility.png
Property getter and setter visibility
EdmDesignerPropertiesPropertyVisibility.png

You have four visibility choices: Public, Internal, Protected, or Private. You can pick any of them if you don't intend to use the model in Silverlight.

Silverlight restrictions

In Silverlight your only viable options are Public and Internal

Silverlight prohibits non-public reflection. Silverlight won't let DevForce reflect for Protected and Private types which means DevForce won't be able to get and set entity data while communicating with the server during queries and saves.

Pick Internal if you want to hide an entity or property in a model that you will use in Silverlight.

Follow the same rule when writing an entity's default constructor.

Make project internals visible to DevForce

Silverlight prevents outside assemblies from accessing internal members, but it makes an exception when the assembly's internals are made visible using the InternalsVisibleTo attribute.

DevForce automatically adds the following to the AssemblyInfo file when the code for a database-first model is generated:

C#
// Allows the expression tree built by DevForce for certain complex queries to be processed correctly.
[assembly: InternalsVisibleTo("System.Core, PublicKey=00240000048000009400000006020000002400005253413100040000010001008d56c76f9e8649383049f383c44be0ec204181822a6c31cf5eb7ef486944d032188ea1d3920763712ccb12d75fb77e9811149e6148e5d32fbaab37611c1878ddc19e20ef135d0cb2cff2bfec3d115810c3d9069638fe4be215dbf795861920e5ab6f7db2e2ceef136ac23d5dd2bf031700aec232f6c6b1c785b4305c123b37ab")]
// Allows internal data members to be serialized.
[assembly: InternalsVisibleTo("System.Runtime.Serialization, PublicKey=00240000048000009400000006020000002400005253413100040000010001008d56c76f9e8649383049f383c44be0ec204181822a6c31cf5eb7ef486944d032188ea1d3920763712ccb12d75fb77e9811149e6148e5d32fbaab37611c1878ddc19e20ef135d0cb2cff2bfec3d115810c3d9069638fe4be215dbf795861920e5ab6f7db2e2ceef136ac23d5dd2bf031700aec232f6c6b1c785b4305c123b37ab")]

DevForce adds these lines to the project's AssemblyInfo automatically when you first generate your entity model. You may have to add them manually if you moved the model to a different model project.

As of version 7.2.0, you also need to grant "friend" access to IdeaBlade.Core.SL to allow DevForce to clone your entities with internal members.  

C#
[assembly: InternalsVisibleTo("IdeaBlade.Core.SL, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b3f302890eb5281a7ab39b936ad9e0eded7c4a41abb440bead71ff5a31d51e865606b2a7e6d0b9dd0d92b113b9d10fb13f01fb5d856e99c1e61777cf4772d29bad7e66ffb93fc5cbd63b395046c06ff57db6ecbeee4bdd6effc405878d65cfc4911708ed650da935d733fc5dc707f74910e025ac080543e01a6cc863b9f85ffc")]


Tags: Model EDM
Created by DevForce on March 23, 2011 13:09

This wiki is licensed under a Creative Commons 2.0 license. XWiki Enterprise 3.2 - Documentation. Copyright © 2020 IdeaBlade