Table of Contents

Class LiteDbHelper

Namespace
AT.Librarys.Container.Utility
Assembly
AT.Librarys.Container.dll

LiteDB 数据库操作类

public class LiteDbHelper
Inheritance
LiteDbHelper
Inherited Members
Extension Methods

Constructors

LiteDbHelper(string)

构造

public LiteDbHelper(string filePath)

Parameters

filePath string

文件路径

LiteDbHelper(string, string)

构造

public LiteDbHelper(string filePath, string password)

Parameters

filePath string

文件路径

password string

密码

LiteDbHelper(string, string, int)

构造

public LiteDbHelper(string filePath, string password, int timeOut)

Parameters

filePath string

文件路径

password string

密码

timeOut int

超时(分钟)

Properties

Connected

连接状态

public bool Connected { get; }

Property Value

bool

Database

LiteDatabase

public LiteDatabaseAsync Database { get; set; }

Property Value

LiteDatabaseAsync

FilePath

文件路径(物理路径,不是连接串)

public string FilePath { get; }

Property Value

string

Methods

CreateConnectString(string, string)

创建连接字符串

public static string CreateConnectString(string folderPath, string databaseName)

Parameters

folderPath string

文件夹路径

databaseName string

数据库名称

Returns

string

Delete(string)

删除

public bool Delete(string tableName)

Parameters

tableName string

Returns

bool

Delete(string, Guid)

删除

public bool Delete(string tableName, Guid id)

Parameters

tableName string
id Guid

Returns

bool

Disconnect()

断开连接

public void Disconnect()

GetDatabase(string)

获取数据库

public LiteDatabaseAsync GetDatabase(string password)

Parameters

password string

Returns

LiteDatabaseAsync

InsertAsync<T>(string, T)

添加数据(异步 fire-and-forget,不建议用于关键路径)

public void InsertAsync<T>(string tableName, T entity) where T : new()

Parameters

tableName string
entity T

Type Parameters

T

Insert<T>(string, T)

添加数据

public string Insert<T>(string tableName, T entity) where T : new()

Parameters

tableName string

表名称

entity T

实体

Returns

string

Type Parameters

T

Query(string)

查询

public object Query(string tableName)

Parameters

tableName string

Returns

object

QueryOne<T>(string, Expression<Func<T, bool>>)

查询

public T QueryOne<T>(string tableName, Expression<Func<T, bool>> predicate) where T : new()

Parameters

tableName string
predicate Expression<Func<T, bool>>

Returns

T

Type Parameters

T

QueryTableName()

查询表名

public List<string> QueryTableName()

Returns

List<string>

Query<T>(string)

查询

public List<T> Query<T>(string tableName) where T : new()

Parameters

tableName string

Returns

List<T>

Type Parameters

T

Query<T>(string, Expression<Func<T, bool>>)

查询

public List<T> Query<T>(string tableName, Expression<Func<T, bool>> predicate) where T : new()

Parameters

tableName string
predicate Expression<Func<T, bool>>

Returns

List<T>

Type Parameters

T

Query<T>(string, string)

查询

public List<T> Query<T>(string tableName, string sn) where T : DataSaveBase, new()

Parameters

tableName string
sn string

Returns

List<T>

Type Parameters

T

Query<T>(string, string, string)

查询

public List<T> Query<T>(string tableName, string startTime, string endTime) where T : DataSaveBase, new()

Parameters

tableName string
startTime string
endTime string

Returns

List<T>

Type Parameters

T

SetNameUnique<T>(string, string, bool)

设置Name属性为唯一索引

public bool SetNameUnique<T>(string tableName, string fieldName, bool unique)

Parameters

tableName string

表名称

fieldName string

字段名称

unique bool

唯一

Returns

bool

Type Parameters

T

Update<T>(string, T)

更新

public bool Update<T>(string tableName, T entity) where T : new()

Parameters

tableName string
entity T

Returns

bool

Type Parameters

T

UpsertAsync<T>(string, T)

更新或添加(异步)

public void UpsertAsync<T>(string tableName, T entity) where T : new()

Parameters

tableName string
entity T

Type Parameters

T

Upsert<T>(string, T)

更新或添加

public bool Upsert<T>(string tableName, T entity) where T : new()

Parameters

tableName string
entity T

Returns

bool

Type Parameters

T