Search code examples
c#c1-cms

Composite C1: How to retrieve data from datatypes?


I'm attempting to create more dynamic slider so I've created a custom datatype which one includes fields like Caption, Text, Link, Image, StartDate, EndDate, Active, etc... I hope I'm in the right path.

Now I need to retrieve active entries. How can I get the necessary entries?


Solution

  • You query data using LINQ through the Get method on the Composite.Data.DataConnection class - dataConnection.Get<T>() where T is your data type wield an IQueryable.

    Below is code that will query a data type named Your.Data.Type, filtering on the Caption field and selecting Caption, Text, Image and StartDate.

    using  (DataConnection connection = new DataConnection())
    {
       var myData = 
          from d in connection.Get<Your.Data.Type>()
          where  d.Caption == "My Caption"
          select new { d.Caption, d.Text, d.Image, d.StartDate };
    }
    

    On the Composite C1 documentation website you can read more about accessing data with C#.

    If you are not into C# you can use either Visual Functions or XSLT Functions.