mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-12-17 17:41:28 +08:00
Update demo
This commit is contained in:
@@ -14,23 +14,44 @@ namespace OrmTest
|
|||||||
Console.WriteLine("");
|
Console.WriteLine("");
|
||||||
Console.WriteLine("#### SimpleClient Start ####");
|
Console.WriteLine("#### SimpleClient Start ####");
|
||||||
|
|
||||||
SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
|
var order = new OrderDal();
|
||||||
{
|
order.GetList();
|
||||||
DbType = DbType.SqlServer,
|
order.GetById(1);
|
||||||
ConnectionString = Config.ConnectionString,
|
order.MyTest();
|
||||||
InitKeyType = InitKeyType.Attribute,
|
|
||||||
IsAutoCloseConnection = true,
|
|
||||||
AopEvents = new AopEvents
|
|
||||||
{
|
|
||||||
OnLogExecuting = (sql, p) =>
|
|
||||||
{
|
|
||||||
Console.WriteLine(sql);
|
|
||||||
Console.WriteLine(string.Join(",", p?.Select(it => it.ParameterName + ":" + it.Value)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Console.WriteLine("#### SimpleClient End ####");
|
Console.WriteLine("#### SimpleClient End ####");
|
||||||
}
|
}
|
||||||
|
public class OrderDal:Repository<Order>
|
||||||
|
{
|
||||||
|
public void MyTest() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class Repository<T> : SimpleClient<T> where T : class, new()
|
||||||
|
{
|
||||||
|
public Repository(ISqlSugarClient context = null) : base(context)//注意这里要有默认值等于null
|
||||||
|
{
|
||||||
|
if (context == null)
|
||||||
|
{
|
||||||
|
base.Context = new SqlSugarClient(new ConnectionConfig()
|
||||||
|
{
|
||||||
|
DbType = SqlSugar.DbType.SqlServer,
|
||||||
|
InitKeyType = InitKeyType.Attribute,
|
||||||
|
IsAutoCloseConnection = true,
|
||||||
|
ConnectionString = Config.ConnectionString
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 扩展方法,自带方法不能满足的时候可以添加新方法
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public List<T> CommQuery(string json)
|
||||||
|
{
|
||||||
|
//base.Context.Queryable<T>().ToList();可以拿到SqlSugarClient 做复杂操作
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user