使用SQLite-net PCL如何分配自定义PrimaryKey?

时间:2017-03-28 20:51:07

标签: sql xamarin sqlite android-sqlite

如何为SQLite行分配字符串作为PrimaryKey? 通常,我使用它来自动增量:

public class BaseItem {
    [PrimaryKey, AutoIncrement]
    public int Name { get; set; }
}

1 个答案:

答案 0 :(得分:0)

你应该可以简单地省略" AutoIncrement"。这就是我们在应用程序中通过设置ctor来实现它的方法:

public class MySuperAwesomeClass
{
  [PrimaryKey]
  public Guid Key { get; set; }

  public MySuperAwesomeClass()
  {
    Key = Guid.NewGuid();
  }
}