如何为与SQLITE相关的主键部署自动分配和递增编号? [英] How to deploy auto-assigning and incrementing number for primary key related to SQLITE?
问题描述
您好,
我遇到了与维护数据库记录的ID条目有关的问题。
看起来当我手动分配它然后创建相关数据然后就可以了。
自动分配似乎不起作用:
Hello,
I face a problem relating to maintaining a ID entry for database records.
It looks like when I assign it manually and then create relevant data then it is ok.
Auto-assignment however does not seem to work:
public class Notification
{
[PrimaryKey, AutoIncrement]
public int N_Id { get; set; }
[MaxLength(250)]
public string Topic { get; set; }
public string Description { get; set; }
public string Tag { get; set; }
}
。
这是在Notification类中维护的。
如果这与public int N_ID的配置有关,或者你遇到类似的问题,请告诉我吗?
祝你好运,
我尝试过:
添加,NotNull在AutoIncrement之后
.
This is maintained in Notification class.
Could you please let me know if this is related to configuration of public int N_ID or if you have faced similar issue?
Best regards,
What I have tried:
Adding ", NotNull" after "AutoIncrement"
推荐答案
从上面的代码中可以看出,你没有为类设置Table属性。
It appears from the above code that you have not set the Table attribute for the class.
[Table(nameof(Notification))]
public class Notification
{
[PrimaryKey, AutoIncrement]
public int N_Id { get; set; }
[MaxLength(250)]
public string Topic { get; set; }
public string Description { get; set; }
public string Tag { get; set; }
}
另外,你是如何创建表的?您是否正在执行以下操作:
Also, how are you creating the Table? Are you doing something like the following:
var conn = new SQLiteConnection(path);
var newTable = conn.CreateTable<Notification>();
这篇关于如何为与SQLITE相关的主键部署自动分配和递增编号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!