问题描述
我完全没有得到这个,因为我已经在Xamarin应用程序中使用了这个库已有多年了。
public class BaseItem
{
[PrimaryKey,AutoIncrement]
public int ID { get; set; } = 0; // sqlite ID
public long CreatedTimeSeconds { get; set; } = DateTime.Now.ToUnixTimeSeconds();
public long ModifiedTimeSeconds { get; set; } = DateTime.Now.ToUnixTimeSeconds();
}
现在,我从中得出:
[Table("CategoryTable")]
public class Category : BaseItem
{
public int CategoryTypeID { get; set; } = (int)CategoryType.Invalid;
public string Name { get; set; } = string.Empty;
public string Description { get; set; } = string.Empty;
}
这是我所看到的简化版本:
public class DBWorld
{
IsqliteService sqlite { get { return DependencyService.Get<IsqliteService>(); } }
private readonly sqliteConnection _conn;
public DBWorld()
{
_conn = sqlite.GetConnection("myapp.sqlite");
}
public void TestThis()
{
_conn.CreateTable<Category>();
var category = new Category();
category.Name = "This Should Work";
int recCount = connection.Insert(category);
// at this point recCount shows as 1,and category.ID shows as zero.
// I thought Insert was supposed to set the autoincrement primary key
// regardless,it should be set in the database,right? So...
var categoryList = connection.Query<Category>($"SELECT * FROM {DBConstants.CategoryTableName}");
// at this point categoryList[0] contains all the expected values,except ID = 0
}
}
我显然很想念什么,但是对于我的一生,我不知道该怎么办...
解决方法
就像在Visual Studio Xamarin世界中发生的许多其他奇异的事情一样,当我稍后返回时,这按我们所有人期望的方式工作。我想Visual Studio太累了,需要重新启动。