FreesqlSimpleExtension 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package FreesqlSimpleExtension --version 1.0.2
                    
NuGet\Install-Package FreesqlSimpleExtension -Version 1.0.2
                    
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.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FreesqlSimpleExtension" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="FreesqlSimpleExtension" />
                    
Project file
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.2
                    
#r "nuget: FreesqlSimpleExtension, 1.0.2"
                    
#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.2
                    
#: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.2
                    
Install as a Cake Addin
#tool nuget:?package=FreesqlSimpleExtension&version=1.0.2
                    
Install as a Cake Tool

FreesqlSimpleExtension

这是一个 FreeSQL 扩展库,旨在简化实体操作和查询构建过程。通过提供一组便捷的扩展方法,使开发者能够更高效地进行数据操作。

仓库地址

GITHUB GITEE

特性

  • 提供便捷的实体修改方法。
  • 支持通过对象模型进行查询构建。
  • 提供多种属性特性用于定义查询条件。

安装

请确保你已经在项目中安装了 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: 定义排序字段。

贡献

欢迎贡献代码和改进。请提交 Pull Request 到主仓库。

许可证

本项目采用 MIT 许可证。详情请查看 LICENSE 文件。

Product 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.

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.

Version Downloads Last Updated
1.0.5 233 5/18/2026
1.0.4 125 5/14/2026
1.0.3 206 8/22/2025
1.0.2 186 7/18/2025
1.0.1 191 7/18/2025
1.0.0 218 7/17/2025