Read only classes and fields

Posted by: the telerik blogs, on 15 Jul 2009 | View original | Bookmarked: 0 time(s)

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> 
 

Lets 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.


Category: Data | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 1776 | Hits: 100

Similar Posts

  • New Entity Framework Feature CTP for VS2010 Beta 2 more
  • Introducing Versatile DataSources more
  • BitLocker To Go more
  • Using T4 Templates for Simple DTOs more
  • Successive Method Calls With MoQ more
  • O# or The Fall Conference Speaking Schedule more
  • True RSS Feed Bankrupcy more
  • Dissecting Lucene.net storage: Documents and Fields more
  • Connect SharePoint Lists (no Web Parts) directly with external LOB data sources more
  • ASP.NET disk-based caching more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD