Method 'SQLiteConnection.InsertAll' not fo

2019-06-08 02:28发布

问题:

I'm trying to get many-to-many database relationships working in my database on (currently) an Android Samsung S6 mobile. To this end I am using SQLite.Net-PCL 3.0.5 and SQLiteNetExtensions 1.3.0. I have had simple SQlite access working fine, but now I have attempted to setup a many to many relationship (via a linking table), the sqlite-net-extensions are throwing when I call m_DatabaseConnection.UpdateWithChildren(article);

The exception is:

System.MissingMethodException: Method 'SQLiteConnection.InsertAll' not found.

Which is weird, as I disassembled the dll and established that it definitely does exist. The structure of my data classes are:

public class Article : BaseModel
{
    public Article()
    {
        Audience = new List<Tag>();
        Content = new List<Tag>();
        Weather = new List<Tag>();
    }

    ...   

    [ManyToMany(typeof(ArticleTag))]
    public List<Tag> Audience { get; set; }
    [ManyToMany(typeof(ArticleTag))]
    public List<Tag> Content { get; set; }
    [ManyToMany(typeof(ArticleTag))]
    public List<Tag> Weather { get; set; }

   ....
}

    public class ArticleTag
{
    [ForeignKey(typeof(Article))]
    public int ArticleID { get; set; }
    [ForeignKey(typeof(Tag))]
    public int TagID { get; set; }
}

public class Tag : BaseModel
{
    ...
}

public class BaseModel
{
    public BaseModel()
    {

    }

    [PrimaryKey, AutoIncrement]
    public int ID { get; set; }

    public bool Dirty { get; set; }
}

So what am I doing wrong? Do I need to include a different version of SQLite.Net-PCL? I tried downloading and compiling the extension project, but there seemed to be errors (I had to unload the iOS projects, as I don't have a licence for iOS, but the rest should have compiled).

Any ideas?

-- Update ---

It seems that the line in question must be within "WriteOperations.cs":

private static void UpdateManyToManyForeignKeys(this SQLiteConnection conn, object element, PropertyInfo relationshipProperty)
    {
...

    conn.InsertAll(missingIntermediateObjects);

    ..
    }

This then goes off to SQLiteExtensions-MvvmCross and must fail to find the implementation of the interface. So, question is, do I need other NuGet packages?

回答1:

So, it looks like it's a combination of misunderstanding how this is intended to work, and 1.3 being broken.

I rolled back to 1.2.5 and it stopped throwing exceptions. But didn't actually save. I then looked at the test cases included within the project source (available here: https://bitbucket.org/twincoders/sqlite-net-extensions) , and saw that he didn't do a straight save on a many-to-many relationship. Instead he inserted the initial entities, then call UpdateWithChildren on the same entities to fill out the linking tables. This seems to work. I'm unclear why this isn't rolled into one call, however it allows me to move on.