Cast CustomTableItem to object

BORAH LEE asked on July 10, 2015 04:18

Hi.

I am trying to develop REST service using ASP.NET WEB API 2 with Kentico 8.1. The functionality that I need is get and post custom table data.

For cast customeTableItem to my own object, I wrote code below but it returns error message 'Unable to cast object of type 'CMS.CustomTables.CustomTableItem' to type 'TestObject '.

What is the best way to convert customTableItem to object?

Thanks.

public class TestObject : CustomTableItem
{
    public const string ClassName = "customtableName";

    public string firstName { get; set; }
    public string LastName { get; set; }
    public string PhoneNumber { get; set; }
    public string Postcode { get; set; }
    public TestObject() : base(ClassName) { }
}



    public IEnumerable<TestObject> GetTestObjects()
    {
        var items = CustomTableItemProvider.GetItems<TestObject>();

        return items.AsEnumerable();
    }

   Please, sign in to be able to submit a new answer.