Hi.Ltd.Sqlite
2026.6.10.1451
dotnet add package Hi.Ltd.Sqlite --version 2026.6.10.1451
NuGet\Install-Package Hi.Ltd.Sqlite -Version 2026.6.10.1451
<PackageReference Include="Hi.Ltd.Sqlite" Version="2026.6.10.1451" />
<PackageVersion Include="Hi.Ltd.Sqlite" Version="2026.6.10.1451" />
<PackageReference Include="Hi.Ltd.Sqlite" />
paket add Hi.Ltd.Sqlite --version 2026.6.10.1451
#r "nuget: Hi.Ltd.Sqlite, 2026.6.10.1451"
#:package Hi.Ltd.Sqlite@2026.6.10.1451
#addin nuget:?package=Hi.Ltd.Sqlite&version=2026.6.10.1451
#tool nuget:?package=Hi.Ltd.Sqlite&version=2026.6.10.1451
Hi.Ltd.SQLite
此类主要与 SQLite数据库进行增删改查方法实现
以下是在C# 中创建表时用到的属性对应到数据库中数据表的结构
自定义候选属性
KeyAtrribute
KeyAtrribute 表示一张表里的主键,此列设置了 [Key] 则默认选择了 [Identity]自增选项 以及 [Reuired] 不可空
[Key]
public int Id{get;set;}
DataBaseAttribute
DataBaseAttribute 表示一张表所在的数据库名称
[DataBase("Hi.Ltd")]
public class Table
{
}
TableAttribute
TableAttribute 表示一张表名称
[Table("Hi.Ltd")]
public class Table
{
}
DatabaseGeneratedAttribute
DatabaseGeneratedAttribute 用于指定主键是否为自增列,如果当前主键未设置则默认为(Data.DatabaseGeneratedOption.Identity)自增列,如果不想设置自增,则需要手动设置
[Key,DatabaseGenerated(Data.DatabaseGeneratedOption.None)]
public int Id{get;set;} //此属性一定是与key 成对出现
[Key,DatabaseGenerated(Data.DatabaseGeneratedOption.Identity)]
public int Id{get;set;} //此设定与 DatabaseGeneratedAttribute未指定时效果一样
MaxLengthAttribute
MaxLengthAttribute 用于指定字符串在长度,如无指定,则默认字符串的长度为50,如果存储到数据库的字段实际长度超过50,则必须指定
[MaxLength(450)]
public string Content{get;set;} //此字段最大长度为450,以Unicode字符形式
public string Note{get;set;} // 此字段最大长度为50,以Unicode字符形式 ,超出或报异常,或截断字符
RequiredAttribute
RequiredAttribute 用于指定当前字段存往数据库中是否可以为空值,如无指定则默认是可以为空值,如指定,则此字段必须不能为空
[Required,MaxLength(450)]
public string Content{get;set;} //此字段不能为空
[MaxLength(450)]
public string Note{get;set;} //此字段可以为空
方法解释
以下是演示数据表示例
[Table("Navigation"), DisplayName("导航表")]
public class NavigationTable
{
[Key, DisplayName("编号")]
public int Id { get; set; }
[DisplayName("日期")]
public DateTime DateTime { get; set; }
[MaxLength(450), DisplayName("内容")]
public string Content { get; set; }
[MaxLength(450), DisplayName("备注")]
public string Note { get; set; }
}
[Table("Login"),DisplayName("登录表")]
public class Login : BaseTable
{
[Key, DisplayName("编号")]
public int Id { get; set; }
[Required, DisplayName("日期")]
public DateTime DateTime { get; set; }
[MaxLength(250),DisplayName("用户名")]
public string UserName { get; set; }
[MaxLength(250),DisplayName("密码")]
public string Password { get; set; }
[ForeignKey(typeof(NavigationTable)),DisplayName("导航编号")]
public int NavigationId { get; set; }
}
CreateDatabase
CreateDatabase 表示创建一个数据库,如果当前数据库不存在则创建,否则跳过
var sql = SqliteEntities.Create; //创建操作句柄
//创建数据库
sql.CreateDatabase(sql.Database); //如无指定路径,则默认存储到 "C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\DATA" 文件夹下
//将创建的数据库存储在指定位置
sql.CreateDatabase(sql.Database,@"C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\DATA");
CreateTable
CreateTable 表示创建一个数据表,如果当前数据表在数据库中已经存在则跳过,否则创建一个新的数据表
sql.CreateTable<NavigationTable>(); //创建导航表
//在指定数据库中使用新的名称来创建导航表
sql.CreateTable<NavigationTable>("NewNavigation"); //创建出来的表在数据库中显示为 [Hi.Ltd].[dbo].[NewNavigation]
sql.CreateTable<Login>(); //创建登录表 ,其它方法使用同上
AlterTable
AlterTable 表示对表结构进行修改的相关操作,此操作具有一定的风险,只可在测试环境下使用,正式环境下不建议使用,此操作不可逆转,如删除无法找回
sql.AlterTable<NavigationTable>(); //此方法将与数据库中的 [Hi.Ltd].[dbo].[Navigation] 进行比对,如果有表成员名称不同,则会在此表中新增一列数据。
//如果名称相同,数据类型不同,则修改表对应成员的数据类型,
//在指定数据库中修改导航表
sql.AlterTable<NavigationTable>("Hi.Ltd");
sql.AlterTable<NavigationTable>("Hi.Ltd","NewNavigation");
sql.AlterTable<NavigationTable>("Hi.Ltd","NewNavigation","hi");
sql.RenameColumn<NavigationTable>("Hi.Ltd","NewNavigation","hi","Note","NewNote"); //将表中的列名[Note]变更 [NewNote] ;
sql.DropColumn<NavigationTable>("Hi.Ltd","Navigation","hi","Note"); //将表中的列名[Note]从表中移除,此操作必须慎重,如需要移除,请确保移除当前数据对程序或其它表没有任何影响;
sql.RenameTable<NavigationTable>("Navigation","NewNavigation"); //将表名称由[Navigation]变更为[NewNavigation]
BackupDatabase
BackupDatabase 对一个已经存在的数据库进行备份操作,如指定的数据不存在,则跳过
sql.BackupDatabase("Hi.Ltd"); //如不指定存储路径则默认存储在"C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\Backup"文件下,
//如无指定文件名称,以指定的数据库名称命令,例如 :Hi.Ltd.bak
sql.BackupDatabase("Hi.Ltd",@"C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\Backup");
sql.BackupDatabase("Hi.Ltd",@"C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\Backup","backup");
RestoreDatabase
RestoreDatabase 从指定的存储路径还原数据库
sql.RestoreDatabase("Hi.Ltd",@"C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\Backup","backup"); //如不指定存储路径则默认存储在"C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\Backup"文件下,
//TODO:其它方法待完善
InsertTable
InsertTable 将数据表里插入一行数据,或批量插入数据
//初始一条数据,由于Id在数据库中设置了自增,所以不需要设置,如没有设置自增则必须设置Id值
var content=new NavigationTable(){
DateTime=DateTime.Now,
Name="这是一个导航表",
Note=string.Empty
};
//初始化多条数据
var content=new List<NavigationTable>()
{
new NavigationTable(){
DateTime=DateTime.Now,
Name="这是一个导航表1",
Note=string.Empty
},
new NavigationTable(){
DateTime=DateTime.Now,
Name="这是一个导航表2",
Note=string.Empty
},
new NavigationTable(){
DateTime=DateTime.Now,
Name="这是一个导航表3",
Note=string.Empty
},
new NavigationTable(){
DateTime=DateTime.Now,
Name="这是一个导航表4",
Note=string.Empty
}
};
sql.InsertTable(content); //将数据库中插入一条数据
//向指定数据库的数据表中插入一条数据
sql.InsertTable("Hi.Ltd",content);
//向指定数据库的指定数据表中插入一条数据
sql.InsertTable("Hi.Ltd","NewNavigation",content);
//向指定数据库的指定架构,指定数据表中插入一条数据
sql.InsertTable("Hi.Ltd","NewNavigation","hi",content);
sql.InsertTable(contents); //将数据库中插入4条数据 ,以下同上
UpdateTable
UpdateTable 将数据表里更新一行数据,或批量更新数据
//初始一条数据,由于更新数据必须指定唯一主键,否则将不能确定此条数据是更新到哪里
var content=new NavigationTable(){
DateTime=DateTime.Now,
Name="这是一个导航表",
Note=string.Empty,
Id=1
};
//初始化多条数据
var content=new List<NavigationTable>()
{
new NavigationTable(){
DateTime=DateTime.Now,
Name="这是一个导航表1",
Note=string.Empty,
Id=2
},
new NavigationTable(){
DateTime=DateTime.Now,
Name="这是一个导航表2",
Note=string.Empty,
Id=3
},
new NavigationTable(){
DateTime=DateTime.Now,
Name="这是一个导航表3",
Note=string.Empty,
Id=4
},
new NavigationTable(){
DateTime=DateTime.Now,
Name="这是一个导航表4",
Note=string.Empty,
Id=5
}
};
sql.UpdateTable(content); //将数据库中更新一条数据
//向指定数据库的数据表中更新一条数据
sql.UpdateTable("Hi.Ltd",content);
//向指定数据库的指定数据表中更新一条数据
sql.UpdateTable("Hi.Ltd","NewNavigation",content);
//向指定数据库的指定架构,指定数据表中更新一条数据
sql.UpdateTable("Hi.Ltd","NewNavigation","hi",content);
sql.UpdateTable(contents); //将数据库中更新4条数据 ,以下同上
//TODO 按条件批量更新整个数据表 待实现中,由于此操作风险过大,不推荐使用
InqureTable
InqureTable 将根据条件查询数据
//默认查询最新的前1000条记录
sql.InqureTable<NavigationTable>();
//向指定数据库的数据表中更新一条数据
sql.InqureTable<NavigationTable>("Hi.Ltd");
//向指定数据库的指定数据表中更新一条数据
sql.InqureTable<NavigationTable>("Hi.Ltd","NewNavigation");
//向指定数据库的指定架构,指定数据表中更新一条数据
sql.InqureTable<NavigationTable>("Hi.Ltd","NewNavigation","hi");
//TODO 按条件查询正在实现中
DropTable
DropTable 从数据库中删除指定的表
//从数据库中删除表
sql.DropTable<NavigationTable>();
//向指定数据库删除表
sql.DropTable<NavigationTable>("Hi.Ltd");
//向指定数据库中删除指定数据表
sql.DropTable<NavigationTable>("Hi.Ltd","NewNavigation");
//向指定数据库中删除指定架构的指定数据表
sql.DropTable<NavigationTable>("Hi.Ltd","NewNavigation","hi");
DeleteTable
DeleteTable 从数据表中删除指定的内容
//TODO 按条件删除正在实现中
以上是已经完成并且测试OK的功能,待实现的功能有数据表内容按条件删除,多表联查,多表联改,多表联删等
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Framework | net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 is compatible. |
-
.NETFramework 4.6.2
- Hi.Ltd (>= 2026.6.10.1407)
- Microsoft.Data.Sqlite (>= 8.0.10)
-
.NETFramework 4.8.1
- Hi.Ltd (>= 2026.6.10.1407)
- Microsoft.Data.Sqlite (>= 8.0.10)
-
net6.0
- Hi.Ltd (>= 2026.6.10.1407)
- Microsoft.Data.Sqlite (>= 8.0.10)
- System.Drawing.Common (>= 8.0.10)
-
net8.0
- Hi.Ltd (>= 2026.6.10.1407)
- Microsoft.Data.Sqlite (>= 8.0.10)
- System.Drawing.Common (>= 8.0.10)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Hi.Ltd.Sqlite:
| Package | Downloads |
|---|---|
|
Hi.Ltd.LocalResource
此类库主要用于文本内容翻译 |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2026.6.10.1451 | 88 | 6/10/2026 |
| 2026.4.14.1758 | 110 | 4/14/2026 |
| 2026.4.14.1613 | 107 | 4/14/2026 |
| 2025.4.17.1101 | 263 | 4/17/2025 |
| 2025.4.16.1536 | 251 | 4/16/2025 |
| 2025.4.16.1410 | 242 | 4/16/2025 |
| 2024.4.16.933 | 262 | 4/16/2025 |
与 Hi.Ltd.SqlServer 主库框架对齐的 SQLite 实现;保留 SQLite 独有能力(去重、备份、WAL、FTS5)。