ShuitNet.ORM.MySQL
1.3.1
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 ShuitNet.ORM.MySQL --version 1.3.1
NuGet\Install-Package ShuitNet.ORM.MySQL -Version 1.3.1
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="ShuitNet.ORM.MySQL" Version="1.3.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ShuitNet.ORM.MySQL" Version="1.3.1" />
<PackageReference Include="ShuitNet.ORM.MySQL" />
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 ShuitNet.ORM.MySQL --version 1.3.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ShuitNet.ORM.MySQL, 1.3.1"
#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 ShuitNet.ORM.MySQL@1.3.1
#: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=ShuitNet.ORM.MySQL&version=1.3.1
#tool nuget:?package=ShuitNet.ORM.MySQL&version=1.3.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
ShuitNet.ORM.MySQL
MySQL用のShuitNet.ORMライブラリです。
概要
ShuitNet.ORM.MySQLは、MySQLデータベースに対応したObject-Relational Mapping (ORM) ライブラリです。シンプルなAPIでMySQLデータベースの操作を簡単に行えます。
特徴
- シンプルなAPI: 直感的で使いやすいメソッド
- 非同期対応: async/awaitパターンをサポート
- 属性ベース設定: データクラスに属性を付与してマッピング設定
- LINQ to SQL: LINQ式を使用したタイプセーフなクエリ
- 命名規則の自動変換: CamelCase, SnakeCase, KebabCase, PascalCaseに対応
- 外部キー対応: ForeignKey属性によるリレーション処理
- トランザクション対応: 安全なデータ操作
インストール
dotnet add package ShuitNet.ORM.MySQL
使用方法
基本的な設定
using ShuitNet.ORM.MySQL;
var connection = new MySQLConnect("Server=localhost;Database=testdb;Uid=user;Pwd=password;");
await connection.OpenAsync();
データクラスの定義
using ShuitNet.ORM.Attribute;
public class User
{
[Key]
public int Id { get; set; }
public string Name { get; set; }
public string Email { get; set; }
[Ignore]
public string TemporaryData { get; set; }
[Serial]
public DateTime CreatedAt { get; set; }
}
基本的なCRUD操作
データの挿入
var user = new User { Name = "John Doe", Email = "john@example.com" };
await connection.InsertAsync(user);
データの取得
// プライマリキーで取得
var user = await connection.GetAsync<User>(1);
// 条件指定で取得
var user = await connection.GetAsync<User>(new { Name = "John Doe" });
// 複数レコードの取得
var users = await connection.GetMultipleAsync<User>(new { Department = "IT" });
// 全件取得
var users = await connection.GetAllAsync<User>();
データの更新
user.Email = "newemail@example.com";
await connection.UpdateAsync(user);
データの削除
await connection.DeleteAsync<User>(1);
カスタムクエリ
// クエリの実行
var users = await connection.QueryAsync<User>("SELECT * FROM users WHERE age > @age", new { age = 18 });
// 単一レコードの取得
var user = await connection.QueryFirstAsync<User>("SELECT * FROM users WHERE email = @email", new { email = "john@example.com" });
// 非クエリの実行
await connection.ExecuteAsync("UPDATE users SET last_login = NOW() WHERE id = @id", new { id = 1 });
LINQ to SQL
LINQ式を使用してタイプセーフなクエリを記述できます:
using ShuitNet.ORM.MySQL.LinqToSql;
// 基本的なクエリ
var users = await connection.AsQueryable<User>()
.Where(u => u.Age > 18)
.OrderBy(u => u.Name)
.ToListAsync();
// JOIN操作
var userOrders = await connection.AsQueryable<User>()
.Join(connection.AsQueryable<Order>(),
u => u.Id,
o => o.UserId,
(u, o) => new { UserName = u.Name, OrderDate = o.Date })
.ToListAsync();
// GROUP BY操作
var stats = await connection.AsQueryable<User>()
.GroupBy(u => u.DepartmentId)
.Select(g => new {
DepartmentId = g.Key,
UserCount = g.Count(),
AverageAge = g.Average(u => u.Age)
})
.ToListAsync();
// 文字列検索
var searchResults = await connection.AsQueryable<User>()
.Where(u => u.Name.Contains("John"))
.Where(u => u.Email.EndsWith(".com"))
.ToListAsync();
命名規則
デフォルトではCamelCaseが使用されますが、以下のように変更できます:
MySQLConnect.NamingCase = NamingCase.SnakeCase;
トランザクション
var transaction = await connection.BeginTransaction();
try
{
await connection.InsertAsync(user1);
await connection.InsertAsync(user2);
await transaction.CommitAsync();
}
catch
{
await transaction.RollbackAsync();
throw;
}
必要なパッケージ
このパッケージは以下のパッケージに依存しています:
- ShuitNet.ORM (コアライブラリ)
- MySqlConnector (MySQLデータベース接続)
ライセンス
このプロジェクトはMITライセンスの下で公開されています。詳細については、LICENSE.txtファイルを参照してください。
作者
shuit (shuit.net)
| 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
- MySql.Data (>= 9.3.0)
- ShuitNet.ORM (>= 1.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.3.14 | 94 | 2/12/2026 |
| 1.3.13 | 96 | 1/14/2026 |
| 1.3.12 | 94 | 1/13/2026 |
| 1.3.11 | 101 | 1/13/2026 |
| 1.3.10 | 102 | 1/13/2026 |
| 1.3.9 | 102 | 1/13/2026 |
| 1.3.8 | 185 | 12/25/2025 |
| 1.3.7 | 177 | 12/22/2025 |
| 1.3.6 | 148 | 11/8/2025 |
| 1.3.5 | 175 | 11/7/2025 |
| 1.3.4 | 197 | 11/5/2025 |
| 1.3.3 | 165 | 11/2/2025 |
| 1.3.2 | 168 | 11/2/2025 |
| 1.3.1 | 135 | 10/31/2025 |
| 1.3.0 | 186 | 10/27/2025 |
| 1.2.0 | 198 | 9/2/2025 |
| 1.0.0 | 191 | 7/1/2025 |