Telerik blogs

If a table or a view is mapped where the user does not have the rights to change data, it is not helpful that the exception is thrown during commit. Sometimes it is hard to find the place where the write access is done. Those exceptions can now be enforced to be thrown during the write operation itself.

The attribute can be set at class level but the wizard does not contain it. In the Q2 release you have to do it by hand, the Q2 Sp1 will contain the UI.

The settings on class level are:

  • "readwrite": The default, everything is allowed.
  • "readonly": Objects of this type cannot be inserted, deleted (scope.Add, scope.Remove) or changed.
  • "insertonly": It is allowed to insert objects of this type (scope.Add) but nothing else.
The insert only setting is useful if you want to write logging data, nobody will be able to manipulate or delete the data via OpenAccess. You have to set all values before you call scope.Add.

To do this setting just open the related app.config file, search for the specific class and add behavior="readonly" to the class node:

<class name="Person" behavior="readonly"
</class> 
 

Let’s have a look at field level. Read only field must be handled more careful. If you set a field to readonly it will not be included into the insert statement. It must be possible to insert the table data without providing data for the underlying column. The setting can be used for fields that are calculated on the server. If you read the field in the next transaction the fields content is fetched from the server and you see the calculated value.

The settings on field level are:

  • "readwrite": The default, everything is allowed.
  • "readonly": The field is not part of the generated insert statement and you cannot change the value.
  • "insertonly": The field is part of the insert statement but you cannot change it later.
The insertonly setting is useful if you want to store a creation timestamp and not change it later. You have to set the value before you call scope.Add.

To do this setting just open the related app.config file, search for the specific class and field and add behavior="readonly" to the field node:

<class name="Person"
  <field name="name" behavior="readonly"
  </field> 
</class> 
 

This is not working for primary key fields, there you have to use the

<extension key="db-key-generator" value="AUTOINC" />  

on class level.



Comments

Comments are disabled in preview mode.