Method 'SQLiteConnection.InsertAll' not found

早过忘川 提交于 2019-12-08 05:38:36

问题


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.



来源:https://stackoverflow.com/questions/33832214/method-sqliteconnection-insertall-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!