Creating the context class

To create the context class, perform the following procedure:

  1. From the context menu of folder Data, click Add » Class...

  2. In the Name input field, enter TestimonialsContext.

  3. Open the file TestimonialsContext.cs and add the following namespaces:

    using Telerik.OpenAccess;
    using Telerik.Sitefinity.Data.OA;

  4. Change the class definition to:

    public class TestimonialsContext : SitefinityOAContext
    {
     
    }

  5. Create the constructor in the following way:

    public TestimonialsContext(string connectionString, BackendConfiguration backendConfig, Telerik.OpenAccess.Metadata.MetadataContainer metadataContainer)
        : base(connectionString, backendConfig, metadataContainer)
    {
     
    }

  6. To get an instance to the context, add the following method:

    public static TestimonialsContext Get()
    {
        return OpenAccessConnection.GetContext(new TestimonialsMetaDataProvider(), "Sitefinity") as TestimonialsContext;
    }

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

Related topics:

Feedback

How useful is this article?

Tell us more

Submit
Your message was successfully sent.

We appreciate your feedback.

Your message could not be sent.

OK