FreesqlSimpleExtension 1.0.4
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package FreesqlSimpleExtension --version 1.0.4
NuGet\Install-Package FreesqlSimpleExtension -Version 1.0.4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FreesqlSimpleExtension" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FreesqlSimpleExtension" Version="1.0.4" />
<PackageReference Include="FreesqlSimpleExtension" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FreesqlSimpleExtension --version 1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: FreesqlSimpleExtension, 1.0.4"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FreesqlSimpleExtension@1.0.4
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FreesqlSimpleExtension&version=1.0.4
#tool nuget:?package=FreesqlSimpleExtension&version=1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
FreesqlSimpleExtension
这是一个 FreeSQL 扩展库,旨在简化实体操作和查询构建过程。通过提供一组便捷的扩展方法,使开发者能够更高效地进行数据操作。
仓库地址
特性
- 提供便捷的实体修改方法。
- 支持通过对象模型进行查询构建。
- 提供多种属性特性用于定义查询条件。
安装
请确保你已经在项目中安装了 FreeSQL。
dotnet add package FreesqlSimpleExtension
使用方法
实体定义
public class TestEntity
{
[Column(IsPrimary = true, IsIdentity = true)]
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public DateTime CreateTime { get; set; }
}
查询输入模型定义
public class TestQueryInput
{
[FsContains]
public string Name { get; set; }
[FsArrayContains(nameof(TestEntity.Name))]
public List<string> NameArray { get; set; }
[FsEq]
public int? AgeEq { get; set; }
[FsArrayContains(nameof(TestEntity.Age))]
public List<int> AgeArray { get; set; }
[FsGte(nameof(TestEntity.Age))]
public int? AgeGte { get; set; }
[FsLte(nameof(TestEntity.Age))]
public int? AgeLte { get; set; }
[FsOrderBy(nameof(TestEntity.Age))]
public List<string> OrderBy { get; set; } = [nameof(TestEntity.Age)];
[FsDateEq]
public DateTime? CreateTime { get; set; }
}
查询使用示例
// 初始化FreeSql实例
var freeSql = new FreeSqlBuilder()
.UseConnectionString(DataType.Sqlite, @"Data Source=test.db")
.UseAutoSyncStructure(true)
.Build();
// 名称包含查询
var query1 = new TestQueryInput { Name = "三" };
var result1 = await freeSql.Select<TestEntity>().QueryEntity(query1).FirstAsync();
// 名称数组包含查询
var query2 = new TestQueryInput { NameArray = ["张三", "李四"] };
var result2 = await freeSql.Select<TestEntity>().QueryEntity(query2).ToListAsync();
// 年龄范围查询
var query3 = new TestQueryInput { AgeGte = 20, AgeLte = 30 };
var result3 = await freeSql.Select<TestEntity>().QueryEntity(query3).ToListAsync();
// 日期相等查询
var query4 = new TestQueryInput { CreateTime = new DateTime(2025, 1, 2) };
var result4 = await freeSql.Select<TestEntity>().QueryEntity(query4).FirstAsync();
// 排序查询
var query5 = new TestQueryInput { OrderBy = ["Age desc"] };
var result5 = await freeSql.Select<TestEntity>().QueryEntity(query5).ToListAsync();
修改示例
你可以使用 ModifyEntity 方法来更新实体对象的属性值。
entity.ModifyEntity(updateModel, isUpdateNull: true, ignoreFields: new[] { "Id" });
查询构建
你可以使用 QueryEntity 方法来根据对象模型构建查询条件。
var result = source.QueryEntity(queryModel);
属性特性
该扩展库提供了一系列属性特性,用于在查询中定义不同的条件:
FsEqAttribute: 等于指定字段。FsGtAttribute: 大于指定字段。FsGteAttribute: 大于等于指定字段。FsLtAttribute: 小于指定字段。FsLteAttribute: 小于等于指定字段。FsContainsAttribute: 包含指定字段。FsArrayContainsAttribute: 数组包含指定字段。FsDateEqAttribute: 日期等于指定字段。FsOrderByAttribute: 定义排序字段。FsNullAttribute: 查询空值字段。FsNotNullAttribute: 查询非空字段。FsRangeAttribute: 查询范围筛选字段。
贡献
欢迎贡献代码和改进。请提交 Pull Request 到主仓库。
许可证
本项目采用 MIT 许可证。详情请查看 LICENSE 文件。
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- FreeSql (>= 3.0.100)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on FreesqlSimpleExtension:
| Package | Downloads |
|---|---|
|
DyForm
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.