ASmile.ORM
3.0.10
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
.NET Framework 4.0
This package targets .NET Framework 4.0. The package is compatible with this framework or higher.
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 ASmile.ORM --version 3.0.10
NuGet\Install-Package ASmile.ORM -Version 3.0.10
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="ASmile.ORM" Version="3.0.10" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ASmile.ORM" Version="3.0.10" />
<PackageReference Include="ASmile.ORM" />
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 ASmile.ORM --version 3.0.10
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: ASmile.ORM, 3.0.10"
#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 ASmile.ORM@3.0.10
#: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=ASmile.ORM&version=3.0.10
#tool nuget:?package=ASmile.ORM&version=3.0.10
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
asmile-orm
介绍
简单、易上手、高效、实用、灵活的 ORM 框架,代码友好,开源、易扩展; nuget: Install-Package ASmile.ORM 目前支持,SQLIte 、SQLServer、MySql、Oracle 数据库; 项目地址:https://gitee.com/zhcun/asmile-orm
示例:
第一步,创建数据库对象
DBContext db = new DBContextDebug(EmDbType.SQLServer, "Server=.;Database=asmile-examples;Trusted_Connection=True;");
新增 1, 使用代码生成器生成的 实体类新增
var r =
db.Insert(new Test01
{
ID = 1,
Name = "张三",
Age = 19,
Birthday = new DateTime(1999, 9, 9),
Balance = 8765.43m,
Remark = ""
});
PrintLog($"新增完成,\nSqlContent:\n{r.SqlContent}");
新增 2 ,使用匿名对象
var r =
db.Insert("Test01",
new
{
ID = 2,
Name = "李四",
Age = 19,
Birthday = new DateTime(1990, 5, 5),
Balance = 9000,
AddTime = DateTime.Now,
Remark = "匿名对象新增"
});
PrintLog($"新增完成,\nSqlContent:\n{r.SqlContent}");
新增 3 ,只对指定字段进行赋值,其它保持数据默认值,如果匿名对象或者实体类对象未对字段属性赋值,则会忽略该字段
var r =
db.Insert(
new Test01
{
ID = 3,
Name = "王五",
//Age = 19,
Birthday = new DateTime(1990, 5, 5),
Balance = 9000,
AddTime = DateTime.Now,
Remark = "年龄未赋值"
});
PrintLog($"新增完成,\nSqlContent:\n{r.SqlContent}");
新增 4 ,批量新增,目前批量新增的效率仅对 Sqlserver 与 MySql 有效,且非空字段必须赋值
List<Test01> addList = new List<Test01>();
for (int i = 0; i < 20; i++)
{
addList.Add(new Test01
{
ID = 4 + i,
Name = $"Name {i + 1}",
Age = 22,
Birthday = new DateTime(2000, 8, 8),
Balance = 1999.56m,
AddTime = DateTime.Now,
Remark = "批量新增"
});
}
db.InsertBulk(addList);
PrintLog($"批量新增完成");
修改 1 ,实体对象,主键更新
//将 ID = 5 的 姓名 该为 刘德华
var r =
db.Update(new Test01
{
ID = 5,
Name = "刘德华",
Remark = ""
});
PrintLog($"修改完成,\nSqlContent:\n{r.SqlContent}");
修改 2,通过 lamda表达式条件修改
//通过 lamda表达式修改,
var r =
db.Update(
new Test01
{
Balance = 500,
Name = "刘玄德",
Remark = "lamda修改"
}, s => s.Name == "Name 3");
PrintLog($"修改完成,\nSqlContent:\n{r.SqlContent}");
修改 3 ,SQL文本赋值方式更新
//SQL文本赋值方式更新
var r =
db.UpdateByExpr<Test01>(s => s.Age < 20,
"Balance = Balance + 250"
);
PrintLog($"修改完成,\nSqlContent:\n{r.SqlContent}");
删除 1 ,按实体类,主键删除
//按实体类主键删除
var r =
db.Delete(new Test01
{
ID = 7
});
PrintLog($"删除完成,\nSqlContent:\n{r.SqlContent}");
删除 2 ,按 lamda 表示条件删除
//使用lamda表达式条件删除
var r =
db.Delete<Test01>(s=>s.Name == "Name 10");
PrintLog($"删除完成,\nSqlContent:\n{r.SqlContent}");
查询 1 ,lamda 表达式,查询首行记录,返回实体对象
// lamda 表达式 查询首行数据
var r = db.Query<Test01>(s => s.ID == 5);
var m = r.ToEntity();
PrintLog($"查询完成,\nSqlContent:\n{r.SqlContent}");
查询 2 ,lamda 表达式 查询列表
// lamda 表达式 查询列表
var r = db.Query<Test01>(s => s.WEx_Like(s.Name, "Name%") && s.ID < 16);
var m = r.ToList();
PrintLog($"查询完成,\nSqlContent:\n{r.SqlContent}");
查询 3,Query对象 灵活查询
// Query对象 灵活查询
var query = db.CreateQuery<Test01>();
string name = "name%";
if (name != "")
{
query.WhereAnd(s => s.WEx_Like(s.Name, $"{name}"));
}
var r = db.Query(query);
var m = r.ToList();
PrintLog($"查询完成,\nSqlContent:\n{r.SqlContent}");
查询 4 ,使用 Query 委托对象 灵活查询
// 使用 Query 委托对象 灵活查询
string name = "name%";
var r = db.Query<Test01>(query =>
{
if (name != "")
{
query.WhereAnd(s => s.WEx_Like(s.Name, $"{name}"));
}
});
var m = r.ToList();
PrintLog($"查询完成,\nSqlContent:\n{r.SqlContent}");
查询 5 ,分页查询,与上述查询方法相同,赋值 参数 PageNo 与 PageSize
// 分页查询
string name = "name%";
var r = db.Query<Test01>(query =>
{
query.PageNo = 2;
query.PageSize = 6;
if (name != "")
{
query.WhereAnd(s => s.WEx_Like(s.Name, $"{name}"));
}
query.OrderBy(s => s.Name); // 姓名排序
});
var m = r.ToList();
PrintLog($"查询完成,\nSqlContent:\n{r.SqlContent}");
查询 6 使用sql文本查询(内置 sql 工具)
//使用sql文本查询(内置 sql 工具)
var r =
db.Query(sql =>
{
int minAge = 15;
int maxAge = 22;
sql.AddSQLParam("select * from Test01 where age > {0} and age < {1}", minAge, maxAge);
});
var rData = r.ToDataTable(); // 返回 DataTable 格式
var rList = r.ToList<Test01>(); // 这里 List 泛型可以使用任何类
PrintLog($"查询完成,\nSqlContent:\n{r.SqlContent}");
存储过程 1 ,匿名对象参数
//存储过程查询
List<Test01> rList =
da.ExecProcedure("P_Query01", new
{
Name = "张三"
}).ToList<Test01>();
PrintLog($"存储过程执行完成");
存储过程 2, 执行
//存储过程执行
da.ExecProcedure("P_Exec01", new
{
Name = "张三"
}).ExecProc();
PrintLog($"存储过程执行完成");
存储过程 3, 执行带返回参数的过程
-- 带输出参数的过程
Create Proc P_Exec02
@Name varchar(20),
@OutMsg varchar(50) = null out
as
delete from Test01 where [Name] = @Name
set @OutMsg = '删除了,' + @Name
// 定义输出参数对象
class OutData
{
public string OutMsg { set; get; } // 输出参数
}
//执行存储过程并返回输出参数值
var retProc =
da.ExecProcedure("P_Exec02", new
{
Name = "张三"
});
OutData outData = new OutData();
retProc.ExecProc(outData);
var msg = outData.OutMsg;
PrintLog($"存储过程执行完成, {msg}");
存储过程 4,执行存储过程并返回输出参数值,匿名对象返回
// 执行存储过程并返回输出参数值,匿名对象返回
var retProc =
da.ExecProcedure("P_Exec02", new
{
Name = "张三"
});
retProc.ExecProc(new { OutMsg = "" });
var msg = retProc.OutObject.OutMsg;
PrintLog($"存储过程执行完成, {msg}");
图文说明:博客园文档
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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 Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net40 is compatible. net403 was computed. net45 was computed. net451 was computed. net452 was computed. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETFramework 4.0
- MySql.Data (>= 6.9.12)
- Oracle.ManagedDataAccess (>= 19.18.0)
- System.Data.SQLite.Core (>= 1.0.110)
-
.NETStandard 2.0
- MySql.Data (>= 8.0.16)
- Oracle.ManagedDataAccess.Core (>= 2.19.180)
- System.Data.SqlClient (>= 4.8.5)
- System.Data.SQLite.Core (>= 1.0.110)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.