Creating the context class
To create the context class, perform the following procedure:
-
From the context menu of folder Data, click Add » Class...
-
In the Name input field, enter TestimonialsContext.
-
Open the file TestimonialsContext.cs and add the following namespaces:
using Telerik.OpenAccess;
using Telerik.Sitefinity.Data.OA;
-
Change the class definition to:
public class TestimonialsContext : SitefinityOAContext
{
}
-
Create the constructor in the following way:
public TestimonialsContext(string connectionString, BackendConfiguration backendConfig, Telerik.OpenAccess.Metadata.MetadataContainer metadataContainer)
: base(connectionString, backendConfig, metadataContainer)
{
}
-
To get an instance to the context, add the following method:
public static TestimonialsContext Get()
{
return OpenAccessConnection.GetContext(new TestimonialsMetaDataProvider(), "Sitefinity") as TestimonialsContext;
}
-
Create property for all testimonials by pasting the following code:
public IQueryable<Testimonial> Testimonials
{
get { return GetAll<Testimonial>(); }
}
You inherit from SitefinityOAContext and reuse the functionality there. You create the Get method to get an instance to the context. Finally, you get all testimonials by calling the GetAll method.