Data Access has been discontinued. Please refer to this page for more information.

Setting DataAccessKind

The DataAccessKind specifies the type of access for the property. It could be:

  • Default - specifies that the default value for the data access kind (read/write) will be used by the runtime.
  • ReadWrite - full access to the property is allowed.
  • ReadOnly - the property is read-only.

You could specify the DataAccessKind for the property, by using the WithDataAccessKind method. In the following example, the FirstName property of the Person class is configured as read-only:

personConfiguration.HasProperty( p => p.FirstName ).
    WithDataAccessKind( Telerik.OpenAccess.DataAccessKind.ReadOnly );
personConfiguration.HasProperty(Function(p) p.FirstName). _
    WithDataAccessKind(Telerik.OpenAccess.DataAccessKind.ReadOnly)

Person Class

public class Person
{
   public int Id {get;set;}
   public string FirstName {get;set;}
   public string LastName {get;set;}
   public string Address {get;set;}
}
Public Class Person
    Private _id As Integer
    Public Property Id() As Integer
        Get
            Return _id
        End Get
        Set(ByVal value As Integer)
            _id = value
        End Set
    End Property

    Private _firstName As String
    Public Property FirstName() As String
        Get
            Return _firstName
        End Get
        Set(ByVal value As String)
            _firstName = value
        End Set
    End Property

    Private _lastName As String
    Public Property LastName() As String
        Get
            Return _lastName
        End Get
        Set(ByVal value As String)
            _lastName = value
        End Set
    End Property

    Private _address As String
    Public Property Address() As String
        Get
            Return _address
        End Get
        Set(ByVal value As String)
            _address = value
        End Set
    End Property
End Class

Sample FluentMetadataSource Implementation - Setting DataAccessKind

public class FluentModelMetadataSource : FluentMetadataSource
{
   protected override IList<MappingConfiguration> PrepareMapping()
   {
       List<MappingConfiguration> configurations = new List<MappingConfiguration>();
       MappingConfiguration<Person> personConfiguration = new MappingConfiguration<Person>();

       personConfiguration.MapType( p => new
       {
           Id = p.Id,
           FirstName = p.FirstName,
           LastName = p.LastName,
           HomeAddress = p.Address
       } ).ToTable( "People" );

       personConfiguration.HasProperty( p => p.Id ).IsIdentity( KeyGenerator.Autoinc );

       personConfiguration.HasProperty( p => p.FirstName ).
            WithDataAccessKind( Telerik.OpenAccess.DataAccessKind.ReadOnly );

       configurations.Add( personConfiguration );
       return configurations;
   }
}
Public Class FluentModelMetadataSource
    Inherits FluentMetadataSource
    Protected Overrides Function PrepareMapping() As _
        System.Collections.Generic.IList(Of Telerik.OpenAccess.Metadata.Fluent.MappingConfiguration)
        Dim configurations As List(Of MappingConfiguration) = New List(Of MappingConfiguration)()
        Dim personConfiguration As New MappingConfiguration(Of Person)()

        personConfiguration.MapType(Function(p) New With {Key .Id = p.Id,
            Key .FirstName = p.FirstName,
            Key .LastName = p.LastName,
            Key .HomeAddress = p.Address}).ToTable("People")

        personConfiguration.HasProperty(Function(p) p.Id).IsIdentity(KeyGenerator.Autoinc)

        personConfiguration.FieldNamingRules.AddPrefix = "_"

        personConfiguration.HasProperty(Function(p) p.FirstName). _
            WithDataAccessKind(Telerik.OpenAccess.DataAccessKind.ReadOnly)

        configurations.Add(personConfiguration)
        Return configurations
    End Function
End Class