1、mysql
1.1、起始配置
appsettings.json中配置mysql连接串
添加类SqlsugarSetup
public static class SqlsugarSetup { public static void AddSqlsugarSetup(this IServiceCollection services, IConfiguration configuration, string dbName = "conStr") { //如果多个数数据库传 List<ConnectionConfig> var configConnection = new ConnectionConfig() { DbType = SqlSugar.DbType.MySql, ConnectionString = configuration.GetConnectionString(dbName), IsAutoCloseConnection = true, }; SqlSugarScope sqlSugar = new SqlSugarScope(configConnection, db => { //单例参数配置,所有上下文生效 db.Aop.OnLogExecuting = (sql, pars) => { //Console.WriteLine(sql);//输出sql }; }); services.AddSingleton<ISqlSugarClient>(sqlSugar);//这边是SqlSugarScope用AddSingleton } }
program中注册服务
builder.Services.AddSqlsugarSetup(builder.Configuration);
利用dbfirst方式引入实体类
db.DbFirst.CreateClassFile("E:\\Learn\\短训\\.NET\\.NET Core\\源码\\sqlsugar\\20240104\\mysqlUseProc\\mysqlUseProc\\Models", "mysqlUseProc.Models");
1.2、调用存储过程
1、带一个输入参数(in)的存储过程
SugarParameter
匿名实例
2、带输入(in)、输出(out)参数的存储过程
2、sql server
使用前需要先进行配置,配置步骤和上述mysql中相似
带输入参数的存储过程
输入、输出参数
输入参数、返回值