sqlsugar 如何使用原生 sql 并添加参数
namespace FY.MysqlService { public class DB { public static string DB_ConnectionString { get; set; } public static string DB_SqlserverConnectionString { get; set; } public static SqlSugarClient db { get => new SqlSugarClient(new ConnectionConfig() { ConnectionString = DB_ConnectionString, DbType = DbType.MySql, IsAutoCloseConnection = true, InitKeyType = InitKeyType.SystemTable, // IsShardSameThread = true } ); } } }
第一种方式:
通过调用 DB.db.Ado.SqlQuery<类名>(" select * from student where stuid=@stuid",new{ stuid=stuid })
第二种方式 :
var s = DB.db.SqlQueryable<bookingTongji>("select * from student where stuid=@stuid").AddParameters(new { stuid=stuid }).ToList() ;