No way to specify class type when performing ...WithChildren operations.

Issue #95 new
Former user created an issue

I have a class called BaseCompany that is used to store data in sqlite in the PCL project. I also have a class called Company that inherits from BaseCompany in an iOS project.

When I attempt to call:

db.InsertWithChildren(company, true); // company is of type Company.

I get "SQLite.Net.SQLiteException: no such table: Company" due to the library attempting to use the table for the super class.

In the regular sqlite.net library, you can work around this issue by adding the type of the class you want to serialize as the last parameter to Insert:

db.Insert(company, typeof(BaseCompany));

Will there be support for this like there is in the regular sqlite.net lib? Something like the following would make sense to me:

db.InsertWithChildren(company, typeof(BaseCompany), true);

Comments (3)

  1. Guillermo GutiƩrrez

    Hey Ryan, thanks for the report. I'll take a look at it and see if it could be included in a future release. I'm not actively developing new functionality, so I can't give you any estimated date. Pull requests are welcome, as always.

  2. Former user Account Deleted reporter

    Thanks Guillermo,

    As a temporary workaround, you can do a Convert call:

                BaseCompany c = (BaseCompany) Convert.ChangeType(company, typeof(BaseCompany));
    
  3. Martin Kuckert

    db.InsertWithChildren((BaseCompany)company, true); should also work. It's not totally easy to support a type parameter because of the recursive nature of the function. But maybe we can add a new method InsertWithChilden<T>(company, true) to do the cast...

  4. Log in to comment