国产优秀ORM框架SqlSugar的使用方法,实例解析
|
SqlSugar是一个轻量级ORM框架,专门用于.NET平台,可以简化数据库操作,提高开发效率。它支持多种数据库,包括MySQL、SqlServer、Oracle等,提供了丰富的功能和灵活的配置选项。
下面将详细介绍SqlSugar的使用方法及其相比其他ORM框架的优点。
一、SqlSugar的安装和配置
1.使用NuGet包管理器安装SqlSugar。<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
</connectionStrings>在Visual<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
</connectionStrings>Studio中,右击项目,选择“管理NuGet程序包”,搜索“SqlSugar”,选择安装。
2.配置数据库连接字符串。<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
</connectionStrings>在app.config或web.config文件中,添加如下配置节:- <connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>
复制代码 3.创建实体类。<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
</connectionStrings>创建一个类,用于映射数据库表的结构,例如:- public<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>class<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>User{<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>public<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>int<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>Id<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>{<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>get;<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>set;<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>}<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>public<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>string<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>Name<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>{<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>get;<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>set;<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>}<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>public<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>int<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>Age<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>{<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>get;<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>set;<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>}}
复制代码 二、SqlSugar的基本用法
1.初始化SqlSugar对象。- using<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>SqlSugar;...var<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>connectionString<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>=<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;var<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>db<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>=<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>new<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>SqlSugarClient(new<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>ConnectionConfig(){<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>ConnectionString<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>=<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>connectionString,<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>DbType<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>=<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>DbType.SqlServer,<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>IsAutoCloseConnection<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>=<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>true,<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>InitKeyType<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>=<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>InitKeyType.Attribute});
复制代码 2.增删改查操作。- //<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>插入数据var<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>user<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>=<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>new<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>User<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>{<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>Name<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>=<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>"张三",<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>Age<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>=<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>20<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>};var<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>id<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>=<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>db.Insertable(user).ExecuteReturnIdentity();//<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>更新数据user.Age<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>=<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>25;db.Updateable(user).ExecuteCommand();//<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>删除数据db.Deleteable().Where(u<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>=><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>u.Id<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>==<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>id).ExecuteCommand();//<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>查询数据var<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>userList<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>=<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>db.Queryable().ToList();
复制代码 3.高级查询。- //<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>条件查询var<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>userList<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>=<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>db.Queryable().Where(u<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>=><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>u.Age<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>18).ToList();//<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>分页查询var<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>userList<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>=<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>db.Queryable().Where(u<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>=><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>u.Age<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>18).ToPageList(1,<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>10,<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>ref<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>totalCount);//<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>排序查询var<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>userList<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>=<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>db.Queryable().OrderBy(u<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>=><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>u.Age,<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>OrderByType.Desc).ToList();//<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>连表查询var<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>userList<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>=<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>db.Queryable((u,<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>o)<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>=><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>new<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>JoinQueryInfos(JoinType.Left,<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>u.Id<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>==<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>o.UserId))<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>.Select((u,<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>o)<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>=><connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>new<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>{<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>u.Name,<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>o.OrderNo<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>})<connectionStrings>
- <add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
- </connectionStrings>.ToList();
复制代码 4.事务操作。三、SqlSugar相比其他ORM框架的优点
- 简单易用。<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
</connectionStrings>SqlSugar提供了简洁的API,可以快速上手,减少学习成本。
- 性能优越。<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
</connectionStrings>SqlSugar采用了一系列优化措施,如缓存、预编译等,提高了数据库操作的性能。
- 支持多种数据库。<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
</connectionStrings>SqlSugar支持多种数据库,可以轻松切换数据库类型,减少了对数据库的依赖。
- 提供丰富的功能。<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
</connectionStrings>SqlSugar提供了丰富的功能,如分页查询、事务操作、连接查询等,满足了各种复杂的业务需求。
- 提供灵活的配置选项。<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
</connectionStrings>SqlSugar提供了许多配置选项,可以根据需求进行灵活配置,满足不同项目的需求。
以上是对SqlSugar的详细介绍及其相比其他ORM框架的优点。通过使用SqlSugar,可以简化数据库操作,提高开发效率。希望以上内容对您有所帮助。
【示例源代码】以上是一个简单的使用SqlSugar的示例代码。
来源:https://www.cnblogs.com/hanbing81868164/archive/2023/11/27/17858332.html
免责声明:由于采集信息均来自互联网,如果侵犯了您的权益,请联系我们【E-Mail:cb@itdo.tech】<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=127.0.0.1;Initial Catalog=TestDB;User ID=sa;Password=123456;" providerName="System.Data.SqlClient" />
</connectionStrings>我们会及时删除侵权内容,谢谢合作! |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
x
|
|
|
发表于 2023-11-27 07:28:31
举报
回复
分享
|
|
|
|