sqlite-net: SQLite.SQLiteException: duplicate column name id in v1.3.3

Hi,

I’m using connection.CreateTableAsync<T>() with a SQLiteAsyncConnection to create tables.

I’ve a base-type for all of my tables:

public abstract class LocalTableBase
{
        [PrimaryKey]
        public virtual int Id { get; set; }
}

In some cases I need a [AutoIncrement] Attribute for Id, so I’m using inheritance like:

public class User : LocalTableBase
{
        [PrimaryKey, AutoIncrement]
        public override int Id { get; set; }
}

This works fine up to v1.3.2 but in v1.3.3 it causes an SQLite.SQLiteException: duplicate column name id

I’m using current Visual Studio 2017 with a Xamarin.Forms App and test against Android (Target Framework Android 7.1) and UWP (Target version: Creators Update). The exception happens on both platforms.

Removing the overriding Properties doe also work, but the tables are created without AutoIncrement for sure. So I think the problem must be in using such a construct.

Thanks for helping.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 4
  • Comments: 27 (2 by maintainers)

Most upvoted comments

This issue shouldn’t be closed because of the number of other issues referring to this one which hasn’t been solved (merely worked around)

Hi,

I tried out v1.4.118 on a fresh Xamarin.Forms App (using Prism Template-Pack and .netstandard2.0 libs) today. The bug is still there and not fixed yet, I think this issue should be reopened.

Luckily the sqlite-net is .Net Standard compatible since v1.3.0 so I was able to use v1.3.2 successfully again.

I ran into the duplicate column issue as well and after stepping thru code, realized that the TableMapping function has a “bug”.

public class Base{
    public int Id { get; set; }
}

public class Derived : Base {
    [Required]
    public new int Id {get; set;}
}

CreateTable<Derived>()

will throw an exception stating Id column is duplicate. The Table mapping function walks thru the inheritance chain collecting the public properties to determine the SQL to be generated.

The workaround that worked for me is to add [Ignore] attribute to the base class like so

public class Base{
      [Ignore]
      public int Id { get; set; }
}

Hope this helps.

After spending some hours doing trail and error, process of elimination, I think I have manage to get this working.

Go to VS Menu -> Project -> Appname Properties -> Android Options -> Linker - Skip linking assemblies and paste in the following

SQLite-net;SQLitePCLRaw.batteries_v2;SQLitePCLRaw.core

Go to VS Menu Build -> Clean Solution.

Build and Deploy.

Why is this issue closed? The problem still exists. The only way for me is to set linking to Sdk Assemblies only, but my app size grows bigger. Could you please reopen it? Or should we open a new issue?

@hvaughan3 Thank you, it worked!