using SqlSugar; using System.Collections.Generic; using System.IO; using System.Linq; namespace Service { public class Repository : SimpleClient where T : class, new() { public Repository(ISqlSugarClient context = null) : base(context)//注意这里要有默认值等于null { if (context == null) { base.Context = new SqlSugarClient(new ConnectionConfig() { DbType = SqlSugar.DbType.MySql, //InitKeyType = InitKeyType.Attribute, IsAutoCloseConnection = true, ConnectionString = InitDB.ConnectionString }); base.Context.Aop.OnLogExecuting = (s, p) => { //Console.WriteLine(s); string param = ""; p.ToList().ForEach(pp => param += $"{pp.ParameterName}={pp.Value};"); //File.AppendAllText(@"f:\sql.txt", s + " | " + param + "\r\n"); //InitDB.OutputDebugString(s+ " | "+ param); }; } } /// /// 扩展方法,自带方法不能满足的时候可以添加新方法 /// /// public List CommQuery(string json) { T t = Context.Utilities.DeserializeObject(json); var list = base.Context.Queryable().WhereClass(t).ToList(); return list; } } }