Search code examples
c#sqlitesharepoint-2010windows-8windows-runtime

SQLite Exception when creating table using OData object containing reference to itself


The following code:

oc.CreateTablesAsync(typeof(ODataService.UserInformationListItem), typeof(ODataService.CategoriesItem), typeof(ODataService.PostsItem));

Gives me this exception:

System.NotSupportedException: Don't know about ODataApp.ODataService.UserInformationListItem

At first I was just creating a table for PostsItems, which is the object i need to store, but then I got the above exception but then for ODataApp.ODataService.CategoriesItem.

Since PostItem has the property Category, which is a List<CategoriesItem> I figured I had to add CategoriesItem as a table as well.

After doing so I got an error for the property CreatedBy on PostsItems, which is a UserInformationListItem, now this is when it gets tricky.

I also added UserInformationListItem to the CreateTables function which gave me my current problem.

The object UserInformationListItem also contains a CreatedBy property which is also an UserInformationListItem.

I'm looking for a way around this without having to alter or recreate local versions of these objects.

These objects are defined on Sharepoint which I cannot edit, and are obtained by the OData service reference. If anymore information is needed to supply me with an answer, please let me know


Solution

  • Based on your sample code I presume you're using sqlite-net.

    Sqlite-net is not a real ORM - it only has support for basic data types and can't handle your custom types as properties. You can check it your self in SqlType() static method of Orm class (SQLite.cs).

    It's not self referencing that's causing problems, it's any references between the classes. Creating tables for the following two classes will fail as well with NotSupportedException:

    public class CategoryItem
    {
        public int Id { get; set; }
        public string Title { get; set; }
    }
    
    public class PostItem
    {
        public int Id { get; set; }
        public string Label { get; set; }
        public List<CategoryItem> Categories { get; set; }
    }
    

    You'll need to create your own "database" classes which will map to database tables one-to-one. To handle UserInformationListItem you'll just add it's key value as a property to PostItem. If PostItem and CategoryItem have a many to many relationship you'll need to add a cross-reference table as well.