SqlSugar源码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.4 KiB

6 years ago
using SqlSugar;
using System;
6 years ago
using System.Collections.Generic;
using System.Linq;
using System.Text;
6 years ago
using System.Threading.Tasks;
6 years ago
6 years ago
namespace OrmTest
6 years ago
{
6 years ago
public class DemoG_SimpleClient
6 years ago
{
6 years ago
public static void Init()
{
6 years ago
Console.WriteLine("");
Console.WriteLine("#### SimpleClient Start ####");
6 years ago
4 years ago
var order = new OrderDal();
order.GetList();
order.GetById(1);
order.MyTest();
2 years ago
var db = new SqlSugarClient(new ConnectionConfig()
{
DbType = SqlSugar.DbType.SqlServer,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
ConnectionString = Config.ConnectionString
});
var repository= db.GetRepository<Repository<Order>>();
var list=repository.GetList();
var repository2 = db.GetRepository<SimpleClient<Order>>();
var list2 = repository2.GetList();
4 years ago
Console.WriteLine("#### SimpleClient End ####");
}
public class OrderDal:Repository<Order>
{
public void MyTest()
{
base.CommQuery("1=1");
base.ChangeRepository<Repository<OrderItem>>().CommQuery("1=1");
4 years ago
}
}
public class Repository<T> : SimpleClient<T> where T : class, new()
{
2 years ago
public Repository()
6 years ago
{
2 years ago
var db = new SqlSugarClient(new ConnectionConfig()
6 years ago
{
2 years ago
DbType = SqlSugar.DbType.SqlServer,
InitKeyType = InitKeyType.Attribute,
IsAutoCloseConnection = true,
ConnectionString = Config.ConnectionString
});
base.Context = db;
db.Aop.OnLogExecuting = (s, p) =>
{
Console.WriteLine(s);
};
4 years ago
}
2 years ago
4 years ago
/// <summary>
/// 扩展方法,自带方法不能满足的时候可以添加新方法
/// </summary>
/// <returns></returns>
public List<T> CommQuery(string sql)
4 years ago
{
//base.Context.Queryable<T>().ToList();可以拿到SqlSugarClient 做复杂操作
return base.Context.Queryable<T>().Where(sql).ToList();
4 years ago
}
6 years ago
6 years ago
}
6 years ago
}
}