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

Querying Artificial Types

This article is relevant to entity models that utilize the deprecated Visual Studio integration of Telerik Data Access. The current documentation of the Data Access framework is available here.

To query artificial types from the database you need to download and use the Dynamic LINQ Library. More information could be found in the Dynamic LINQ topic.

The Dynamic LINQ extension methods are brought in to scope by using/import the System.Linq.Dynamic namespace.

The following example demonstrates how to use the GetAll and FieldValue<T> extension methods from the Telerik.OpenAccess namespace. The GetAll method returns an IQueryable endpoint, which allows you to write dynamic LINQ queries against artificial persistent types. The FieldValue<T> extension method returns the value for the specified artificial field.

using ( FluentModelContext fluentContext = new FluentModelContext() )
   IQueryable result = fluentContext.GetAll( "FluentModel.Category" ).
       Where( string.Format( "Id < {0}", 10 ) );
   foreach ( object category in result )
       Console.WriteLine( category.FieldValue<string>( "CategoryName" ) );
Using fluentContext As New FluentModelContext()
    Dim result As IQueryable = fluentContext.GetAll("FluentModel.Category").
        Where(String.Format("Id < {0}", 10))

    For Each category As Object In result
        ' Extension methods on objects should be called as static methods
        ' due to limitations in VB
        Dim categoryName As String = Telerik.OpenAccess.ExtensionMethods.
            FieldValue(Of String)(category, "CategoryName")
    Next category

End Using

Accessing Property Values

The generic extension method FieldValue<T> from the Telerik.OpenAccess namespace allows you to access the value for a persistent type property. The method accepts a single string parameter containing the name of the persistent field whose value will be returned.

Console.WriteLine( product.FieldValue<string>( "CategoryName" ) );
Dim categoryName As String = Telerik.OpenAccess.ExtensionMethods.FieldValue(Of String)(category, "CategoryName")