use*_*er1 5 c# sqlite indexing sqlite.net
我正在使用该属性构建移动应用程序,Sqlite.Net并且遇到了该Indexed属性。这在示例中显示:https ://github.com/praeclarum/sqlite-net#example-time
public class Stock
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
[MaxLength(8)]
public string Symbol { get; set; }
}
public class Valuation
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
[Indexed]
public int StockId { get; set; }
public DateTime Time { get; set; }
public decimal Price { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,该StockId列被标记为,Indexed但是在查询表时,肯定会由Sqlite引擎来确定索引并优化查询。
所以我的问题是该Indexed属性的用途是什么以及我是否需要它?
但是当查询表时,肯定会由 Sqlite 引擎来确定索引
不可以,索引必须预先定义并通过插入、更新和删除来维护。当查询运行时,引擎可以决定使用或忽略哪些索引,但不能创建索引。
所以[Indexed]外键上的属性是适当的手动优化。
| 归档时间: |
|
| 查看次数: |
5136 次 |
| 最近记录: |