.NET 开源SqlServer ORM框架 SqlSugar 3.0 API
3.1.x ,将作为3.X系统的最后一个版本,下面将会开发 全新的功能
更新列表:https://github.com/sunkaixuan/SqlSugar/releases
优点:
SqlSugar 是一款小巧,并且功能齐全的ORM,并不需要像Dapper一样依赖第三方扩展
SqlSugar 语法易用简单 ,有漂亮的拉姆达语法,也支持Dapper SQL和ADO.NET的所有功能
SqlSugar 性能达到原生水准,远超 Dapper和EF CORE。
SqlSugar 支持.NET CORE , 多个数据库
SqlSugar 体积小巧只有150K是EF的30分之1 ,NUGET直接可以下载
特色功能
SqlbulkCopy和SqlbulkReplace 这两个函数能够处理海量数据插入和更新 ,也是众多ORM没有集成的功能之一
SQL日志功能 可以方便的对SQL进行监控和写入日志
全局过滤器 例如我都有IsDeleted来标识是否删 除, 这样我每查一个表就 要加一个WHERE条件 ,有了全局过滤器就变成非常方便
T4+实体生成 可以自定义实体格式 并且可以能过T4模版快速生成实体文件
POCO设计 实体类没有任何属性完全原生态
所有版本:
ASP.NET 4.0+ MSSQL https://github.com/sunkaixuan/SqlSugar
ASP.NET CORE MSSQL https://github.com/sunkaixuan/ASP_NET_CORE_ORM_SqlSugar
ASP.NET 4.0+ MYSQL https://github.com/sunkaixuan/MySqlSugar
ASP.NET CORE MYSQL https://github.com/sunkaixuan/ASP_NET_CORE_ORM_MySqlSugar
ASP.NET 4.0+ Sqlite https://github.com/sunkaixuan/SqliteSugar
ASP.NET CORE Sqlite https://github.com/sunkaixuan/ASP_NET_CORE_ORM_MySqlSugar
ASP.NET 4.0+ ORACLE https://github.com/sunkaixuan/OracleSugar
连接数据库
1.简单用法
using(var db = new SqlSugarClient(ConnectionString)){ //use object
var list=db.Queryable<T>().ToList(); }
2.打包用法,推荐
/// <summary>
/// SqlSugar
/// </summary>
public class SugarDao
{
private SugarDao()
{ }
public static string ConnectionString
{
get
{
string reval = "server=.;uid=sa;pwd=sasa;database=SqlSugarTest";
return reval;
}
}
public static SqlSugarClient GetInstance()
{
var db = new SqlSugarClient(ConnectionString);
db.IsEnableLogEvent = true;//Enable log events
db.LogEventStarting = (sql, par) => { Console.WriteLine(sql + " " + par+"\r\n"); };
return db;
}
}
使用打包对象
using (var db = SugarDao.GetInstance())
{
var list=db.Queryable<T>().ToList();
}
3.高级玩法,基于IOC和指挥官模式的DEMO
https://github.com/sunkaixuan/ASPNETMVCCRUDDEMO
0、功能预览
/****************************基本功能**************************************/
//查询
case "select": demo = new Select(); break;
//删除
case "delete": demo = new Delete(); break;
//插入
case "insert": demo = new Insert(); break;
//更新
case "update": demo = new Update(); break;
//基层函数的用法
case "ado": demo = new Ado(); break;
//事务
case "tran": demo = new Tran(); break;
//创建实体函数
case "createclass": demo = new CreateClass(); break;
//T4生成 http://www.cnblogs.com/sunkaixuan/p/5751503.html //日志记录
case "log": demo = new Log(); break;
//枚举支持
case "enum": demo = new EnumDemo(); break; /****************************实体映射**************************************/
//自动排除非数据库列
case "ignoreerrorcolumns": demo = new IgnoreErrorColumns(); break;
//别名表
case "mappingtable":demo=new MappingTable(); break;
//别名列
case "mappingcolumns": demo = new MappingColumns(); break;
//通过属性的方法设置别名表和别名字段
case "attributesmapping": demo = new AttributesMapping(); break; /****************************业务应用**************************************/
//过滤器
case "filter": demo = new Filter(); break;
//过滤器2
case "filter2": demo = new Filter2(); break;
//流水号功能
case "serialnumber": demo = new SerialNumber(); break; //多语言支持 http://www.cnblogs.com/sunkaixuan/p/5709583.html
//多库并行计算 http://www.cnblogs.com/sunkaixuan/p/5046517.html /****************************支持**************************************/
//公开函数数
case "pubmethod": demo = new PubMethod(); break;
//Sql2012分页的支持
case "sqlpagemodel": demo=new SqlPageModel(); break;
//设置ToJson的日期格式
case "serializerdateformat":demo =new SerializerDateFormat();break; default: Console.WriteLine("switchOn的值错误,请输入正确的 case"); break;
1、使用拉姆达进行查询
//查询所有
var student = db.Queryable<Student>().ToList();
var studentDynamic = db.Queryable<Student>().ToDynamic();
var studentJson = db.Queryable<Student>().ToJson(); //查询单条
var single = db.Queryable<Student>().Single(c => c.id == );
//查询单条根据主键
var singleByPk = db.Queryable<Student>().InSingle();
//查询单条没有记录返回空对象
var singleOrDefault = db.Queryable<Student>().SingleOrDefault(c => c.id == );
//查询单条没有记录返回空对象
var single2 = db.Queryable<Student>().Where(c => c.id == ).SingleOrDefault(); //查询第一条
var first = db.Queryable<Student>().Where(c => c.id == ).First();
var first2 = db.Queryable<Student>().Where(c => c.id == ).FirstOrDefault(); //取11-20条
var page1 = db.Queryable<Student>().Where(c => c.id > ).OrderBy(it => it.id).Skip().Take().ToList(); //取11-20条 等于 Skip(pageIndex-1)*pageSize).Take(pageSize) 等于 between (pageIndex-1)*pageSize and pageIndex*pageSize
var page2 = db.Queryable<Student>().Where(c => c.id > ).OrderBy(it => it.id).ToPageList(, ); //查询条数
var count = db.Queryable<Student>().Where(c => c.id > ).Count(); //从第2条开始以后取所有
var skip = db.Queryable<Student>().Where(c => c.id > ).OrderBy(it => it.id).Skip().ToList(); //取前2条
var take = db.Queryable<Student>().Where(c => c.id > ).OrderBy(it => it.id).Take().ToList(); //Not like
string conval = "a";
var notLike = db.Queryable<Student>().Where(c => !c.name.Contains(conval.ToString())).ToList(); //Like
conval = "三";
var like = db.Queryable<Student>().Where(c => c.name.Contains(conval)).ToList(); //支持字符串Where 让你解决,更复杂的查询
var student12 = db.Queryable<Student>().Where(c => "a" == "a").Where("id>@id", new { id = }).ToList();
var student13 = db.Queryable<Student>().Where(c => "a" == "a").Where("id>100 and id in( select 1)").ToList(); //存在记录反回true,则否返回false
bool isAny100 = db.Queryable<Student>().Any(c => c.id == );
bool isAny1 = db.Queryable<Student>().Any(c => c.id == ); //获取最大Id
object maxId = db.Queryable<Student>().Max(it => it.id);
int maxId1 = db.Queryable<Student>().Max(it => it.id).ObjToInt();//拉姆达
int maxId2 = db.Queryable<Student>().Max<int>("id"); //字符串写法 //获取最小
int minId1 = db.Queryable<Student>().Where(c => c.id > ).Min(it => it.id).ObjToInt();//拉姆达
int minId2 = db.Queryable<Student>().Where(c => c.id > ).Min<int>("id");//字符串写法 //order By
var orderList = db.Queryable<Student>().OrderBy("id desc,name asc").ToList();//字符串支持多个排序
//可以多个order by表达示
var order2List = db.Queryable<Student>().OrderBy(it => it.name).OrderBy(it => it.id, OrderByType.desc).ToList(); // order by name as ,order by id desc //In
var intArray = new[] { "", "", "" };
var intList = intArray.ToList();
var listnew = db.Queryable<Student>().Where(it => intArray.Contains(it.name)).ToList();
var list0 = db.Queryable<Student>().In(it => it.id, , , ).ToList();
var list1 = db.Queryable<Student>().In(it => it.id, intArray).ToList();
var list2 = db.Queryable<Student>().In("id", intArray).ToList();
var list3 = db.Queryable<Student>().In(it => it.id, intList).ToList();
var list4 = db.Queryable<Student>().In("id", intList).ToList();
var list6 = db.Queryable<Student>().In(intList).ToList();//不设置字段默认主键 //分组查询
var list7 = db.Queryable<Student>().Where(c => c.id < ).GroupBy(it => it.sex).Select("sex,count(*) Count").ToDynamic();
var list8 = db.Queryable<Student>().Where(c => c.id < ).GroupBy(it => it.sex).GroupBy(it => it.id).Select("id,sex,count(*) Count").ToDynamic();
List<StudentGroup> list9 = db.Queryable<Student>().Where(c => c.id < ).GroupBy(it => it.sex).Select<StudentGroup>("Sex,count(*) Count").ToList();
List<StudentGroup> list10 = db.Queryable<Student>().Where(c => c.id < ).GroupBy("sex").Select<StudentGroup>("Sex,count(*) Count").ToList();
//SELECT Sex,Count=count(*) FROM Student WHERE 1=1 AND (id < 20) GROUP BY Sex --生成结果 //2表关联查询
var jList = db.Queryable<Student>()
.JoinTable<School>((s1, s2) => s1.sch_id == s2.id) //默认left join
.Where<School>((s1, s2) => s1.id == )
.Select("s1.*,s2.name as schName")
.ToDynamic(); /*等于同于
SELECT s1.*,s2.name as schName
FROM [Student] s1
LEFT JOIN [School] s2 ON s1.sch_id = s2.id
WHERE s1.id = 1 */ //2表关联查询并分页
var jList2 = db.Queryable<Student>()
.JoinTable<School>((s1, s2) => s1.sch_id == s2.id) //默认left join
//如果要用inner join这么写
//.JoinTable<School>((s1, s2) => s1.sch_id == s2.id ,JoinType.INNER)
.Where<School>((s1, s2) => s1.id > )
.OrderBy(s1 => s1.name)
.Skip()
.Take()
.Select("s1.*,s2.name as schName")
.ToDynamic(); //3表查询并分页
var jList3 = db.Queryable<Student>()
.JoinTable<School>((s1, s2) => s1.sch_id == s2.id) // left join School s2 on s1.id=s2.id
.JoinTable<School>((s1, s3) => s1.sch_id == s3.id) // left join School s3 on s1.id=s3.id
.Where<School>((s1, s2) => s1.id > ) // where s1.id>1
.Where(s1 => s1.id > )
.OrderBy<School>((s1, s2) => s1.id) //order by s1.id 多个order可以 .oderBy().orderby 叠加
.Skip()
.Take()
.Select("s1.*,s2.name as schName,s3.name as schName2")//select目前只支持这种写法
.ToDynamic(); //上面的方式都是与第一张表join,第三张表想与第二张表join写法如下
List<V_Student> jList4 =
db.Queryable<Student>()
.JoinTable<School>((s1, s2) => s1.sch_id == s2.id) // left join School s2 on s1.id=s2.id
.JoinTable<School, Area>((s1, s2, a1) => a1.id == s2.AreaId)// left join Area a1 on a1.id=s2.AreaId 第三张表与第二张表关联
.JoinTable<Area, School>((s1, a1, s3) => a1.id == s3.AreaId)// left join School s3 on a1.id=s3.AreaId 第四第表第三张表关联
.JoinTable<School>((s1, s4) => s1.sch_id == s4.id) // left join School s2 on s1.id=s4.id
.Select<School, Area, V_Student>((s1, s2, a1) => new V_Student { id = s1.id, name = s1.name, SchoolName = s2.name, AreaName = a1.name }).ToList(); //等同于
//SELECT id = s1.id, name = s1.name, SchoolName = s2.name, AreaName = a1.name
//FROM [Student] s1
//LEFT JOIN School s2 ON ( s1.sch_id = s2.id )
//LEFT JOIN Area a1 ON ( a1.id = s2.AreaId ) //第三张表与第二张表关联
//LEFT JOIN School s3 ON ( a1.id = s3.AreaId ) //第四张表与第三张表关联
//LEFT JOIN School s4 ON ( s1.sch_id = s4.id )
//WHERE 1=1 //Join子查询语句加分页的写法
var childQuery = db.Queryable<Area>().Where("id=@id").Select(it => new { id = it.id }).ToSql();//创建子查询SQL
string childTableName =SqlSugarTool.PackagingSQL(childQuery.Key);//将SQL语句用()包成表
var queryable = db.Queryable<Student>()
.JoinTable<School>((s1, s2) => s1.sch_id == s2.id) //LEFT JOIN School s2 ON ( s1.sch_id = s2.id )
.JoinTable(childTableName, "a1", "a1.id=s2.areaid", new { id = }, JoinType.INNER) //INNER JOIN (SELECT * FROM [Area] WHERE 1=1 AND id=@id ) a1 ON a1.id=s2.areaid
.OrderBy(s1 => s1.id); var list = queryable.Select<School, Area, V_Student>((s1, s2, a1) => new V_Student { id = s1.id, name = s1.name, SchoolName = s2.name, AreaName = a1.name })
.ToPageList(, );
var count2 = queryable.Count(); //拼接例子
var queryable2 = db.Queryable<Student>().Where(it => true);
if (maxId.ObjToInt() == )
{
queryable2.Where(it => it.id == );
}
else
{
queryable2.Where(it => it.id == );
}
var listJoin = queryable2.ToList(); //queryable和SqlSugarClient解耦
var par = new Queryable<Student>().Where(it => it.id == );//声名没有connection对象的Queryable
par.DB = db;
var listPar = par.ToList(); //查看生成的sql和参数
var id = ;
var sqlAndPars = db.Queryable<Student>().Where(it => it.id == id).OrderBy(it => it.id).ToSql(); //拉姆达支持的函数操作
var par1 = "2015-1-1"; var par2 = " 我 有空格A, ";
var r1 = db.Queryable<Student>().Where(it => it.name == par1.ObjToString()).ToList(); //ObjToString会将null转转成""
var r2 = db.Queryable<InsertTest>().Where(it => it.d1 == par1.ObjToDate()).ToList();
var r3 = db.Queryable<InsertTest>().Where(it => it.id == .ObjToInt()).ToList();//ObjToInt会将null转转成0
var r4 = db.Queryable<InsertTest>().Where(it => it.id == .ObjToDecimal()).ToList();
var r5 = db.Queryable<InsertTest>().Where(it => it.id == .ObjToMoney()).ToList();
var r6 = db.Queryable<InsertTest>().Where(it => it.v1 == par2.Trim()).ToList();
var convert1 = db.Queryable<Student>().Where(c => c.name == "a".ToString()).ToList();
var convert2 = db.Queryable<Student>().Where(c => c.id == Convert.ToInt32("")).ToList();
var convert3 = db.Queryable<Student>().Where(c => c.name == par2.ToLower()).ToList();
var convert4 = db.Queryable<Student>().Where(c => c.name == par2.ToUpper()).ToList();
var convert5= db.Queryable<Student>().Where(c => DateTime.Now > Convert.ToDateTime("2015-1-1")).ToList();
var c1 = db.Queryable<Student>().Where(c => c.name.Contains("a")).ToList();
var c2 = db.Queryable<Student>().Where(c => c.name.StartsWith("a")).ToList();
var c3 = db.Queryable<Student>().Where(c => c.name.EndsWith("a")).ToList();
var c4 = db.Queryable<Student>().Where(c => !string.IsNullOrEmpty(c.name)).ToList();
var c5 = db.Queryable<Student>().Where(c => c.name.Equals("小杰")).ToList();
var c6 = db.Queryable<Student>().Where(c => c.name.Length > ).ToList();
var time = db.Queryable<InsertTest>().Where(c => c.d1>DateTime.Now.AddDays()).ToList();
var time2 = db.Queryable<InsertTest>().Where(c => c.d1 > DateTime.Now.AddYears()).ToList();
var time3 = db.Queryable<InsertTest>().Where(c => c.d1 > DateTime.Now.AddMonths()).ToList();
2、使用原生SQL查询
//转成list
List<Student> list1 = db.SqlQuery<Student>("select * from Student");
//转成list带参
List<Student> list2 = db.SqlQuery<Student>("select * from Student where id=@id", new { id = });
//转成dynamic
dynamic list3 = db.SqlQueryDynamic("select * from student");
//转成json
string list4 = db.SqlQueryJson("select * from student");
//返回int
var list5 = db.SqlQuery<int>("select top 1 id from Student").SingleOrDefault();
//反回键值
Dictionary<string, string> list6 = db.SqlQuery<KeyValuePair<string, string>>("select id,name from Student").ToDictionary(it => it.Key, it => it.Value);
//反回List<string[]>
var list7 = db.SqlQuery<string[]>("select top 1 id,name from Student").SingleOrDefault();
//存储过程
var spResult = db.SqlQuery<School>("exec sp_school @p1,@p2", new { p1 = , p2 = }); //存储过程加Output
var pars = SqlSugarTool.GetParameters(new { p1 = ,p2= }); //将匿名对象转成SqlParameter
db.IsClearParameters = false;//禁止清除参数
pars[].Direction = ParameterDirection.Output; //将p2设为 output
var spResult2 = db.SqlQuery<School>("exec sp_school @p1,@p2 output", pars);
db.IsClearParameters = true;//启动请动清除参数
var outPutValue = pars[].Value;//获取output @p2的值 //获取第一行第一列的值
string v1 = db.GetString("select '张三' as name");
int v2 = db.GetInt("select 1 as name");
double v3 = db.GetDouble("select 1 as name");
decimal v4 = db.GetDecimal("select 1 as name");
3、SQL高级拼接器写法
using (var db = SugarDao.GetInstance())
{
//---------Sqlable,创建多表查询---------// //多表查询
List<School> dataList = db.Sqlable()
.From("school", "s")
.Join("student", "st", "st.id", "s.id", JoinType.INNER)
.Join("student", "st2", "st2.id", "st.id", JoinType.LEFT)
.Where("s.id>100 and s.id<@id")
.Where("1=1")//可以多个WHERE
.OrderBy("id")
.SelectToList<School/*新的Model我这里没有所以写的School*/>("st.*", new { id = }); //多表分页
List<School> dataPageList = db.Sqlable()
.From("school", "s")
.Join("student", "st", "st.id", "s.id", JoinType.INNER)
.Join("student", "st2", "st2.id", "st.id", JoinType.LEFT)
.Where("s.id>100 and s.id<100")
.SelectToPageList<School>("st.*", "s.id", , ); //多表分页WHERE加子查询
List<School> dataPageList2 = db.Sqlable()
.From("school", "s")
.Join("student", "st", "st.id", "s.id", JoinType.INNER)
.Join("student", "st2", "st2.id", "st.id", JoinType.LEFT)
.Where("s.id>100 and s.id<100 and s.id in (select 1 )" /*这里面写子查询都可以*/)
.SelectToPageList<School>("st.*", "s.id", , ); //--------转成List Dynmaic 或者 Json-----// //不分页
var list1 = db.Sqlable().From("student", "s").Join("school", "l", "s.sch_id", "l.id and l.id=@id", JoinType.INNER).SelectToDynamic("*", new { id = });
var list2 = db.Sqlable().From("student", "s").Join("school", "l", "s.sch_id", "l.id and l.id=@id", JoinType.INNER).SelectToJson("*", new { id = });
var list3 = db.Sqlable().From("student", "s").Join("school", "l", "s.sch_id", "l.id and l.id=@id", JoinType.INNER).SelectToDataTable("*", new { id = }); //分页
var list4 = db.Sqlable().From("student", "s").Join("school", "l", "s.sch_id", "l.id and l.id=@id", JoinType.INNER).SelectToPageDynamic("s.*", "l.id", , , new { id = });
var list5 = db.Sqlable().From("student", "s").Join("school", "l", "s.sch_id", "l.id and l.id=@id", JoinType.INNER).SelectToPageTable("s.*", "l.id", , , new { id = });
var list6 = db.Sqlable().From("student", "s").Join("school", "l", "s.sch_id", "l.id and l.id=@id", JoinType.INNER).SelectToPageDynamic("s.*", "l.id", , , new { id = }); //--------拼接-----//
Sqlable sable = db.Sqlable().From<Student>("s").Join<School>("l", "s.sch_id", "l.id", JoinType.INNER);
string name = "a";
int id = ;
if (!string.IsNullOrEmpty(name))
{
sable = sable.Where("s.name=@name");
}
if (!string.IsNullOrEmpty(name))
{
sable = sable.Where("s.id=@id or s.id=100");
}
if (id > )
{
sable = sable.Where("l.id in (select top 10 id from school)");//where加子查询
}
var pars = new { id = id, name = name };
int pageCount = sable.Count(pars);
var list7 = sable.SelectToPageList<Student>("s.*", "l.id desc", , , pars); }
4、更新
//指定列更新
db.Update<School>(new { name = "蓝翔14" }, it => it.id == ); //只更新name列
db.Update<School, int>(new { name = "蓝翔11 23 12", areaId = }, , , );
db.Update<School, string>(new { name = "蓝翔2" }, new string[] { "", "" });
db.Update<School>(new { name = "蓝翔2" }, it => it.id == ); //支持字典更新,适合动态权限
var dic = new Dictionary<string, string>();
dic.Add("name", "第十三条");
dic.Add("areaId", "");
db.Update<School, int>(dic, ); //整个实体更新
db.Update(new School { id = , name = "蓝翔16", AreaId = });
db.Update<School>(new School { id = , name = "蓝翔12", AreaId = }, it => it.id == );
db.Update<School>(new School() { id = , name = "青鸟11" }); //设置不更新列
db.DisableUpdateColumns = new string[] { "CreateTime" };//设置CreateTime不更新 TestUpdateColumns updObj = new TestUpdateColumns()
{
VGUID = Guid.Parse("542b5a27-6984-47c7-a8ee-359e483c8470"),
Name = "xx",
Name2 = "xx2",
IdentityField = ,
CreateTime = null
}; //CreateTime将不会被更新
db.Update(updObj);
//以前实现这种更新需要用指定列的方式实现,现在就简单多了。 //批量更新 数据量小时建议使用
var updateResult = db.UpdateRange(GetUpdateList()); //批量更新 数据量大时建议使用
var updateResult2 = db.SqlBulkReplace(GetUpdateList2());
5、删除和状态删除
//删除
db.Delete<School, int>();
db.Delete<School>(it => it.id > );
//主键批量删除
db.Delete<School, string>(new string[] { "", "", "" });
//非主键批量删除
db.Delete<School, string>(it => it.name, new string[] { "" });
db.Delete<School, int>(it => it.id, new int[] { , }); //假删除
//db.FalseDelete<school>("is_del", 100);
//等同于 update school set is_del=1 where id in(100)
//db.FalseDelete<school>("is_del", it=>it.id==100);
6、插入
db.Insert(GetInsertItem()); //插入一条记录 (有主键也好,没主键也好,有自增列也好都可以插进去) db.InsertRange(GetInsertList()); //批量插入 支持(别名表等功能) db.SqlBulkCopy(GetInsertList()); //批量插入 适合海量数据插入,要求实体与数据库一致,不支持(别名表、排除列等功能) //设置不插入列
db.DisableInsertColumns = new string[] { "sex" };//sex列将不会插入值
Student s = new Student()
{
name = "张" + new Random().Next(, int.MaxValue),
sex = "gril"
};
var id = db.Insert(s); //插入
//查询刚插入的sex是否有值
var sex = db.Queryable<Student>().Single(it => it.id == id.ObjToInt()).sex;//无值
var name = db.Queryable<Student>().Single(it => it.id == id.ObjToInt()).name;//有值
7、枚举支持
var stuList = db.Queryable<Student>().ToList();
db.Insert<Student>(new Student() { sch_id = SchoolEnum.北大青鸟 });
db.Update<Student>(new Student() { sch_id = SchoolEnum.it清华, id = });
var stuList2 = db.Queryable<Student>().Where(it => it.sch_id == SchoolEnum.全智).ToList();
8、实体生成加T4
//可以结合别名表,请看别名表的用法
//db.SetMappingTables(mappingTableList); db.ClassGenerating.CreateClassFiles(db, ("e:/TestModels"), "Models"); //只生成student和school表的实体
db.ClassGenerating.CreateClassFilesByTableNames(db, "e:/TestModels2", "Models", new string[] { "student", "school" }); //根据表名生成class字符串
var str = db.ClassGenerating.TableNameToClass(db, "Student"); var dynamicToClassStr = db.ClassGenerating.DynamicToClass(new { id = }, "dyName"); //根据SQL语句生成class字符串
var str2 = db.ClassGenerating.SqlToClass(db, "select top 1 * from Student", "student"); //改变值(lassTemplate.ItemTemplate=XXXX)可以自定义格式
var tempItem = ClassTemplate.ItemTemplate;//例如可以在生成的实体添加默认构造函数给指定的字段赋默认值或者公司信息等
var temp = ClassTemplate.Template; //设置新格式模板
//主键Guid.New(),
//CreateTime为DateTime.Now
//IsRemove=0
//UpdateTime为DateTime.Now
ClassTemplate.Template = "using System;\r\nusing System.Linq;\r\nusing System.Text;\r\n\r\nnamespace $namespace\r\n{\r\n public class $className\r\n {\r\n public $className() \r\n { \r\n this.CreateTime = DateTime.Now;\r\n this. = 0;\r\n this.UpdateTime=DateTime.Now;\r\n this.$primaryKeyName=Guid.NewGuid().ToString(\"N\").ToUpper();\r\n }\r\n $foreach\r\n }\r\n}\r\n"; //新格式的实体字符串
var str3 = db.ClassGenerating.TableNameToClass(db, "Student");
使用T4
详细教程:
http://www.cnblogs.com/sunkaixuan/p/5751503.html
9、ADO.NET
var r1 = db.GetDataTable("select * from student");
var r2 = db.GetSingle<Student>("select top 1 * from student");
var r3 = db.GetScalar("select count(1) from student");
var r4 = db.GetReader("select count(1) from student");
r4.Dispose();
var r5 = db.GetString("select top 1 name from student");
var r6 = db.ExecuteCommand("select 1"); //参数支持
var p1 = db.GetDataTable("select * from student where id=@id", new {id= });
var p2 = db.GetDataTable("select * from student where id=@id", new Dictionary<string, object>() { { "id", "" } });//目前只支持 Dictionary<string, object>和Dictionary<string, string>
var p3 = db.GetDataTable("select * from student where id=@id", new SqlParameter("@id",) );
10、日志记录功能
//日志记录功能
public class Log : IDemos
{ public void Init()
{
Console.WriteLine("启动Log.Init");
using (var db = SugarDemoDao.GetInstance())
{ var a1 = db.Queryable<Student>().Where(it => it.id == ).ToList();
var a2 = db.Queryable<Student>().OrderBy(it => it.id).ToList();
}
} public class SugarConfigs
{
public static Action<string, string> LogEventStarting = (sql, pars) =>
{
Console.WriteLine("starting:" + sql + " " + pars); using (var db = SugarDemoDao.GetInstance())
{
//日志记录件事件里面用到数据库操作 IsEnableLogEvent一定要为false否则将引起死循环,并且要新开一个数据实例 像我这样写就没问题。
db.IsEnableLogEvent = false;
db.ExecuteCommand("select 1");
}
};
public static Action<string, string> LogEventCompleted = (sql, pars) =>
{
Console.WriteLine("completed:" + sql + " " + pars);
};
} /// <summary>
/// SqlSugar
/// </summary>
public class SugarDemoDao
{ public static SqlSugarClient GetInstance()
{
var db = new SqlSugarClient(SugarDao.ConnectionString);
db.IsEnableLogEvent = true;//启用日志事件
db.LogEventStarting = SugarConfigs.LogEventStarting;
db.LogEventCompleted = SugarConfigs.LogEventCompleted;
return db;
}
}
}
}
11、别名表功能
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NewTest.Dao;
using Models;
using System.Data.SqlClient;
using SqlSugar;
namespace NewTest.Demos
{
//别名表的功能
public class MappingTable : IDemos
{ public void Init()
{
Console.WriteLine("启动MappingTable.Init"); //单个设置
using (var db = SugarDao.GetInstance())
{
var list = db.Queryable<V_Student>("Student").ToList();//查询的是 select * from student 而我的实体名称为V_Student
} //全局设置
using (var db = SugarFactory.GetInstance())
{
var list = db.Queryable<V_Student>().ToList();//查询的是 select * from student 而我的实体名称为V_Student
}
} /// <summary>
/// 全局配置类
/// </summary>
public class SugarConfigs
{
//key类名 value表名
public static List<KeyValue> MpList = new List<KeyValue>(){
new KeyValue(){ Key="FormAttr", Value="Flow_FormAttr"},
new KeyValue(){ Key="Student3", Value="Student"},
new KeyValue(){ Key="V_Student", Value="Student"}
};
} /// <summary>
/// SqlSugar实例工厂
/// </summary>
public class SugarFactory
{ //禁止实例化
private SugarFactory()
{ }
public static SqlSugarClient GetInstance()
{
string connection = SugarDao.ConnectionString; //这里可以动态根据cookies或session实现多库切换
var db = new SqlSugarClient(connection);
db.SetMappingTables(SugarConfigs.MpList);//设置关联表 (引用地址赋值,每次赋值都只是存储一个内存地址)
return db;
}
}
}
}
12别名列功能
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NewTest.Dao;
using System.Data.SqlClient;
using SqlSugar;
namespace NewTest.Demos
{
//别名列的功能
public class MappingColumns : IDemos
{ public void Init()
{
Console.WriteLine("启动MappingColumns.Init"); //全局设置
using (var db = SugarFactory.GetInstance())
{
var list = db.Queryable<Student>().Where(it=>it.classId==).ToList();
}
} public class Student
{ //id
public int classId { get; set; } //name
public string className { get; set; } //sch_id
public int classSchoolId { get; set; } public int isOk { get; set; }
} /// <summary>
/// 全局配置别名列(不区分表)
/// </summary>
public class SugarConfigs
{
//key实体字段名 value表字段名 ,KEY唯一否则异常
public static List<KeyValue> MpList = new List<KeyValue>(){
new KeyValue(){ Key="classId", Value="id"},
new KeyValue(){ Key="className", Value="name"},
new KeyValue(){ Key="classSchoolId", Value="sch_id"}
};
} /// <summary>
/// SqlSugar实例工厂
/// </summary>
public class SugarFactory
{ //禁止实例化
private SugarFactory()
{ }
public static SqlSugarClient GetInstance()
{
string connection = SugarDao.ConnectionString; //这里可以动态根据cookies或session实现多库切换
var db = new SqlSugarClient(connection);
//注意:只有启动属性映射才可以使用SetMappingColumns
db.IsEnableAttributeMapping = true;
db.SetMappingColumns(SugarConfigs.MpList);//设置关联列 (引用地址赋值,每次赋值都只是存储一个内存地址)
return db;
}
}
}
}
13通过属性来设置别名表和别名列
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NewTest.Dao;
using Models;
using System.Data.SqlClient;
using SqlSugar;
namespace NewTest.Demos
{
//通过属性的方法设置别名表和别名字段(主键和自添列都无需设置 SQLSUGAR会帮你自动处理)
//注意:【属性映射和 (SetMappingTables、SetMappingColumns)方式映射 2种选其中一,不清楚底层缓存机质不建议同时使用】
public class AttributesMapping : IDemos
{ public void Init()
{
Console.WriteLine("启动AttributesMapping.Init");
using (var db = DBManager.GetInstance())
{ //查询
var list = db.Queryable<TestStudent>()
.Where(it => it.className.Contains("小")).OrderBy(it => it.classSchoolId).Select<V_Student>(it => new V_Student() { id = it.classId, name = it.className }).ToList();
var list2 = db.Queryable<TestStudent>()
.JoinTable<TestSchool>((s1, s2) => s1.classSchoolId == s2.classId)
.OrderBy<TestSchool>((s1, s2) => s1.classId)
.Select<TestStudent, TestSchool, V_Student>((s1, s2) => new V_Student() { id = s1.classId, name = s1.className, SchoolName = s2.className }).ToList(); //添加
TestStudent s = new TestStudent();
s.className = "属性名";
s.classSchoolId = ;
var id = db.Insert(s);
s.classId = id.ObjToInt(); //更新
db.Update(s);
db.Update<TestStudent, int>(s, );
db.Update<TestStudent>(s, it => it.classId == );
db.SqlBulkReplace(new List<TestStudent>() { s }); //删除
db.Delete<TestStudent>(it => it.classId == );
}
} /// <summary>
/// 属性只作为初始化映射,SetMappingTables和SetMappingColumns可以覆盖
/// </summary>
[SugarMapping(TableName = "Student")]
public class TestStudent
{ [SugarMapping(ColumnName = "id")]
public int classId { get; set; } [SugarMapping(ColumnName = "name")]
public string className { get; set; } [SugarMapping(ColumnName = "sch_id")]
public int classSchoolId { get; set; } public int isOk { get; set; } /// <summary>
/// 数据库并没有这一列
/// </summary>
public string errorField { get; set; }
} [SugarMapping(TableName = "School")]
public class TestSchool
{ [SugarMapping(ColumnName = "id")]
public int classId { get; set; } [SugarMapping(ColumnName = "name")]
public string className { get; set; } public int AreaId = ;
}
} public class DBManager
{ public static SqlSugarClient GetInstance()
{
var db = new SqlSugarClient(SugarDao.ConnectionString);
db.IsEnableAttributeMapping = true;//启用属性映射
db.IsIgnoreErrorColumns = true;//忽略非数据库列 db.IsEnableLogEvent = true;//启用日志事件
db.LogEventStarting = (sql, par) => { Console.WriteLine(sql + " " + par + "\r\n"); }; return db;
}
}
}
14、行列过滤 (行过滤器可以设置多个,以逗号隔开)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NewTest.Dao;
using Models;
using System.Data.SqlClient;
using SqlSugar; namespace NewTest.Demos
{
//行过滤加列过滤
//权限管理的最佳设计
public class Filter2 : IDemos
{ public void Init()
{
Console.WriteLine("启动Filter2.Init");
using (SqlSugarClient db = SugarDaoFilter.GetInstance())//开启数据库连接
{
//设置走哪个过滤器
db.CurrentFilterKey = "role1";
//queryable
var list = db.Queryable<Student>().ToJson(); //where id=1 , 可以查看id和name //设置走哪个过滤器
db.CurrentFilterKey = "role2";
//queryable
var list2 = db.Queryable<Student>().ToJson(); //where id=2 , 可以查看name }
}
/// <summary>
/// 扩展SqlSugarClient
/// </summary>
public class SugarDaoFilter
{
//禁止实例化
private SugarDaoFilter()
{ }
/// <summary>
/// 页面所需要的过滤行
/// </summary>
private static Dictionary<string, Func<KeyValueObj>> _filterParas = new Dictionary<string, Func<KeyValueObj>>()
{
{ "role1",()=>{
return new KeyValueObj(){ Key=" id=@id" , Value=new{ id=}};
}
},
{ "role2",()=>{
return new KeyValueObj() { Key = " id=@id", Value = new { id = } };
}
},
};
/// <summary>
/// 页面所需要的过滤列
/// </summary>
private static Dictionary<string, List<string>> _filterColumns = new Dictionary<string, List<string>>()
{
{ "role1",new List<string>(){"id","name"}
},
{ "role2",new List<string>(){"name"}
},
};
public static SqlSugarClient GetInstance()
{
string connection = SugarDao.ConnectionString; //这里可以动态根据cookies或session实现多库切换
var reval = new SqlSugarClient(connection); //支持sqlable和queryable
reval.SetFilterFilterParas(_filterParas); //列过滤只支持queryable
reval.SetFilterFilterParas(_filterColumns);
return reval;
}
}
}
}
15、自动排除非数据库列
//排除错误列
public class IgnoreErrorColumns : IDemos
{ public void Init()
{
Console.WriteLine("启动IgnoreErrorColumns.Init");
using (var db = SugarDao.GetInstance())
{
db.IsIgnoreErrorColumns = true; //Student表并没有 AreaName
var id= db.Insert<STUDENT>(new STUDENT() { name = "张三", AreaName = "北大" }); db.Update<STUDENT>(new STUDENT() { id=id.ObjToInt() ,name = "张三2", AreaName = "北大" });
}
}
public class STUDENT {
/// <summary>
/// Desc:-
/// Default:-
/// Nullable:False
/// </summary>
public int id { get; set; } /// <summary>
/// Desc:-
/// Default:-
/// Nullable:True
/// </summary>
public string name { get; set; } /// <summary>
/// Desc:学校ID
/// Default:-
/// Nullable:True
/// </summary>
public int? sch_id { get; set; } /// <summary>
/// Desc:-
/// Default:-
/// Nullable:True
/// </summary>
public string sex { get; set; } /// <summary>
/// Desc:-
/// Default:-
/// Nullable:True
/// </summary>
public Boolean? isOk { get; set; } public string SchoolName { get; set; } public string AreaName { get; set; } public string SubjectName { get; set; }
}
}
16、事务
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NewTest.Dao;
using Models;
using System.Data.SqlClient;
using SqlSugar; namespace NewTest.Demos
{
//事务
public class Tran : IDemos
{ public void Init()
{
Console.WriteLine("启动Tran.Init");
using (SqlSugarClient db = SugarDao.GetInstance())//开启数据库连接
{
db.IsNoLock = true;//启用无锁查询
db.CommandTimeOut = ;//设置超时时间
try
{
db.BeginTran();//开启事务
//db.BeginTran(IsolationLevel.ReadCommitted);+3重载可以设置事世隔离级别 db.CommitTran();//提交事务
}
catch (Exception)
{
db.RollbackTran();//回滚事务
throw;
}
}
}
}
}
17、流水号功能
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NewTest.Dao;
using Models;
using System.Data.SqlClient;
using SqlSugar; namespace NewTest.Demos
{
//流水号的功能
public class SerialNumber : IDemos
{ public void Init()
{
Console.WriteLine("启动SerialNumber.Init");
using (SqlSugarClient db = SugarFactory.GetInstance())//开启数据库连接
{
var dientityValue = db.Insert<Student>(new Student() { });
var name = db.Queryable<Student>().Single(it => it.id == dientityValue.ObjToInt()).name;
Console.WriteLine(name); var dientityValue2 = db.Insert<School>(new School() { });
var name2 = db.Queryable<School>().Single(it => it.id == dientityValue2.ObjToInt()).name;
Console.WriteLine(name2); ;
}
} /// <summary>
/// 全局配置类
/// </summary>
public class SugarConfigs
{
public static List<PubModel.SerialNumber> NumList = new List<PubModel.SerialNumber>(){
new PubModel.SerialNumber(){TableName="Student", FieldName="name", GetNumFunc=()=>{ //GetNumFunc在没有事中使用
return "stud-"+DateTime.Now.ToString("yyyy-MM-dd");
}},
new PubModel.SerialNumber(){TableName="School", FieldName="name", GetNumFuncWithDb=db=>{ //事务中请使用GetNumFuncWithDb保证同一个DB对象,不然会出现死锁
return "ch-"+DateTime.Now.ToString("syyyy-MM-dd");
}}
};
} /// <summary>
/// SqlSugar实例工厂
/// </summary>
public class SugarFactory
{ //禁止实例化
private SugarFactory()
{ }
public static SqlSugarClient GetInstance()
{
string connection = SugarDao.ConnectionString; //这里可以动态根据cookies或session实现多库切换
var db = new SqlSugarClient(connection);
db.SetSerialNumber(SugarConfigs.NumList);//设置流水号
return db;
}
}
}
}
18、多库并行计算功能
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SqlSugar;
using System.Configuration;
using System.Data;
using System.Threading.Tasks;
using System.Transactions;
using System.Threading; namespace WebTest.Demo
{
/// <summary>
/// /*******************************************************************分布式计算 demo**************************************************************/
/// </summary>
public partial class Cloud : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var id = Guid.Parse("4FC950EC-7C23-480F-9545-443EBDCA32E9");
int pageCount = ; using (CloudClient db = CloudDao.GetInstance())
{
db.PageMaxHandleNumber = ;
using (CommittableTransaction trans = new CommittableTransaction())//启用分布式事务
{ db.Tran = trans; /*** 增、删、改 ***/ //根据配置的百分比,随机插入到某个节点库
var s = new student()
{
createTime = DateTime.Now,
id = Guid.NewGuid(),
name = Guid.NewGuid() + ""
};
//db.Insert<student>(s, false/*false表示不是自增列*/); //数据库设计主键为GUID为佳多库计算不会冲突 ////并发请求所有节点找出这条数据更新
//s.name = "改11";
//db.Update<student>(s, it => it.id == s.id);//根据表达示更新 //db.Update<student, Guid>(s, s.id);//根据主键更新 //db.Update<student, Guid>(s, new Guid[] { s.id });//根据主键数组更新 ////并发请求所有节点找出这条数据删除
//db.Delete<student>(it => it.id == s.id); trans.Commit();
} db.TranDispose(); /*** 使用Taskable实现云计算 ***/ //多线程请求所有数据库节点,获取汇总结果
var taskDataTable = db.Taskable<DataTable>("SELECT max(NUM) FROM STUDENT").Tasks;
foreach (var dr in taskDataTable)//遍历所有节点数据
{
var dt = dr.Result.DataTable;//每个节点的数据 类型为DataTable
var connectionName = dr.Result.ConnectionString;
} //多线程请求所有数据库节点,获取汇总结果
var taskInt = db.Taskable<int>("SELECT max(NUM) FROM STUDENT").Tasks;
foreach (var dr in taskInt)//遍历所有节点数据
{
var dt = dr.Result.Value;//获取单个值
var connectionName = dr.Result.ConnectionString;
} //多线程请求所有数据库节点,获取汇总结果
var taskEntity = db.Taskable<student>("SELECT top 100 * FROM STUDENT").Tasks;
foreach (var dr in taskEntity)//遍历所有节点数据
{
var dt = dr.Result.Entities;//获取实体集合
var connectionName = dr.Result.ConnectionString;
} // //Taskable实现分组查询
// var groupList = db.Taskable<DataTable>("SELECT name,COUNT(*) AS [count],AVG(num) as num FROM STUDENT WHERE ID IS NOT NULL GROUP BY NAME ")
// .Tasks
// .SelectMany(it => it.Result.DataTable.AsEnumerable())
// .Select(dr => new { num = Convert.ToInt32(dr["NUM"]), name = dr["NAME"].ToString(), count = Convert.ToInt32(dr["COUNT"]) })
// .GroupBy(dr => dr.name).Select(dt => new { name = dt.First().name, count = dt.Sum(dtItem => dtItem.count), num = dt.Sum(dtItem => dtItem.num) / dt.Sum(dtItem => dtItem.count) }).ToList(); // //输出结果
// foreach (var it in groupList)
// {
// var num = it.num;
// var name = it.name;
// var count = it.count;
// } // //简化
// var groupList2 = db.Taskable<DataTable>("SELECT NAME,COUNT(*) AS [COUNT],AVG(NUM) as NUM FROM STUDENT WHERE ID IS NOT NULL GROUP BY NAME ")
//.MergeTable()//将结果集合并到一个集合
//.Select(dr => new { num = Convert.ToInt32(dr["NUM"]), name = dr["NAME"].ToString(), count = Convert.ToInt32(dr["COUNT"]) })
//.GroupBy(dr => dr.name).Select(dt => new { name = dt.First().name, count = dt.Sum(dtItem => dtItem.count), num = dt.Sum(dtItem => dtItem.num) / dt.Sum(dtItem => dtItem.count) }).ToList(); // //再简化
// List<V_Student> groupList3 = db.Taskable<V_Student>("SELECT name,COUNT(*) AS [count],AVG(num) as num FROM STUDENT WHERE ID IS NOT NULL GROUP BY NAME ")
//.MergeEntities()//将结果集合并到一个集合
//.GroupBy(dr => dr.name).Select(dt => new V_Student { name = dt.First().name, count = dt.Sum(dtItem => dtItem.count), num = dt.Sum(dtItem => dtItem.num) / dt.Sum(dtItem => dtItem.count) }).ToList(); //更多简化函数
int maxValue = db.Taskable<int>("SELECT max(NUM) FROM STUDENT").Max();//求出所有节点的最大值
int minValue = db.Taskable<int>("SELECT min(NUM) FROM STUDENT").Min();//求出所有节点的最小值
var dataCount = db.Taskable<int>("SELECT count(1) FROM STUDENT").Count();//求出所有节点数据
// var avg = db.TaskableWithCount<int>("SELECT avg(num)", " FROM STUDENT").Avg();
var all = db.Taskable<student>("select * from student where Contains(name,@name)"/*使用contains需要建全文索引*/, new { name = "张三" }).ToList();//获取所有节点name为张三的数据,转为list var dnSingle = DateTime.Now;
var data = db.Taskable<student>("select * from student where id=@id", new { id = id }).ToSingle();//从所有节点中查询一条记录
var timeSingle = (DateTime.Now - dnSingle).TotalSeconds; var dn = DateTime.Now;
//单列排序
// var list = db.TaskableWithPage<student>("id", "select * from student "/*使用contains需要建全文索引*/, 2160, 25, ref pageCount, "num", OrderByType.desc, new { name = "\"*李*\"" });
var time = (DateTime.Now - dn).TotalSeconds; //多组排序 order by num,time
var dn2 = DateTime.Now;
var listMultipleOrderBy = db.TaskableWithPage<student>("id", "select * from student "/*使用contains需要建全文索引*/, , , ref pageCount, new List<OrderByDictionary>() {
new OrderByDictionary(){ OrderByField="num", OrderByType=OrderByType.asc},
// new OrderByDictionary(){ OrderByField="createTime", OrderByType=OrderByType.desc},
// new OrderByDictionary(){ OrderByField="createTime", OrderByType=OrderByType.asc}
}, new { name = "\"*小*\"" });
var time2 = (DateTime.Now - dn2).TotalSeconds; }
}
/// <summary>
/// 测试类
/// </summary>
public class student
{
public Guid id { get; set; }
public string name { get; set; }
public DateTime createTime { get; set; }
public int num { get; set; }
}
/// <summary>
/// 获取数据库连接对象
/// </summary>
public class CloudDao
{
private CloudDao() { }
public static CloudClient GetInstance()
{
return new CloudClient(new List<CloudConnectionConfig>() {
new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["c1"].ToString(), Rate=},
new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["c2"].ToString(), Rate=},
new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["c3"].ToString(), Rate=},
new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["c4"].ToString(), Rate=},
new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["c5"].ToString(), Rate=},
new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["c6"].ToString(), Rate=},
new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["c7"].ToString(), Rate=},
new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["c8"].ToString(), Rate=},
new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["c9"].ToString(), Rate=},
new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["c10"].ToString(), Rate=},
new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["c15"].ToString(), Rate=},
new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["c16"].ToString(), Rate=},
new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["c17"].ToString(), Rate=},
//new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["cy1"].ToString(), Rate=1},
// new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["cy2"].ToString(), Rate=1},
// new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["cy3"].ToString(), Rate=1},
// new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["zq1"].ToString(), Rate=1},
// new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["zq2"].ToString(), Rate=1},
// new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["zq3"].ToString(), Rate=1},
// new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["qp1"].ToString(), Rate=1},
// new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["qp2"].ToString(), Rate=1},
// new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["qp3"].ToString(), Rate=1},
// new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["wy1"].ToString(), Rate=1},
// new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["wy2"].ToString(), Rate=1},
// new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["wy3"].ToString(), Rate=1},
// new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["wwf1"].ToString(), Rate=1},
// new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["wwf2"].ToString(), Rate=1},
// new CloudConnectionConfig(){ ConnectionString=ConfigurationManager.ConnectionStrings["wwf3"].ToString(), Rate=1}, });
}
}
}
}
19添加VS知能提示,让你立马上手。
http://www.cnblogs.com/sunkaixuan/p/5851425.html
GITHUB下载地址:
所有版本
ASP.NET 4.0+ MSSQL https://github.com/sunkaixuan/SqlSugar
ASP.NET CORE MSSQL https://github.com/sunkaixuan/ASP_NET_CORE_ORM_SqlSugar
ASP.NET 4.0+ MYSQL https://github.com/sunkaixuan/MySqlSugar
ASP.NET CORE MYSQL https://github.com/sunkaixuan/ASP_NET_CORE_ORM_MySqlSugar
ASP.NET 4.0+ Sqlite https://github.com/sunkaixuan/SqliteSugar
ASP.NET CORE Sqlite https://github.com/sunkaixuan/ASP_NET_CORE_ORM_MySqlSugar
ASP.NET 4.0+ ORACLE https://github.com/sunkaixuan/OracleSugar
.NET 开源SqlServer ORM框架 SqlSugar 3.0 API的更多相关文章
- .Net开源SqlServer ORM框架SqlSugar整理
一.链接整理 官方Git源代码地址: https://github.com/sunkaixuan/SqlSugar 最新发布版更新地址:当前版本Release 3.5.2.1 https://gith ...
- LitepalNewDemo【开源数据库ORM框架-LitePal2.0.0版本的使用】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 本Demo使用的是LitePal2.0.0版本,对于旧项目如何升级到2.0.0版本,请阅读<赶快使用LitePal 2.0版本 ...
- [Android]Android端ORM框架——RapidORM(v2.0)
以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/5626716.html [Android]Android端ORM ...
- ORM框架--GreenDao 3.0基本使用指南
0. ORM框架--GreenDao 3.0基本使用指南 1. Gradle 的配置 这里可以参照官方的文档进行最新的配置(本示例的版本等你看到可能就不是最新的了),但是值得注意的一点是,GreenD ...
- [Android]Android端ORM框架——RapidORM(v1.0)
以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/4748077.html Android上主流的ORM框架有很多 ...
- .Net开源微型ORM框架测评
什么是ORM? 对象关系映射(英语:Object Relation Mapping,简称ORM,或O/RM,或O/R mapping),是一种程序技术,用于实现面向对象编程语言里不同类型系统的数据之间 ...
- [开源] .Net orm FreeSql 1.5.0 最新版本(番号:好久不见)
废话开头 这篇文章是我有史以来编辑最长时间的,历时 4小时!!!原本我可以利用这 4小时编写一堆胶水代码,真心希望善良的您点个赞,谢谢了!! 很久很久没有写文章了,上一次还是在元旦发布 1.0 版本的 ...
- [开源] .Net ORM FreeSql 1.10.0 稳步向行
写在开头 FreeSql 是 .NET 开源生态下的 ORM 轮子,转眼快两年了,说真的开源不容易(只有经历过才明白).今天带点干货和湿货给大家,先说下湿货. 认识我的人,知道 CSRedisCore ...
- Asp.Net 高性能ORM框架 SqlSugar.ORM 2.8
3.0最新API: http://www.cnblogs.com/sunkaixuan/p/5911334.html 1.前言/Preface SqlSugar从去年到现在已经一年了,版本从1.0升到 ...
随机推荐
- Xamarin+Prism开发详解三:Visual studio 2017 RC初体验
Visual studio 2017 RC出来一段时间了,最近有时间就想安装试试,随带分享一下安装使用体验. 1,卸载visual studio 2015 虽然可以同时安装visual studio ...
- 使用RequireJS并实现一个自己的模块加载器 (一)
RequireJS & SeaJS 在 模块化开发 开发以前,都是直接在页面上引入 script 标签来引用脚本的,当项目变得比较复杂,就会带来很多问题. JS项目中的依赖只有通过引入JS的顺 ...
- 6.在MVC中使用泛型仓储模式和依赖注入实现增删查改
原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-operations-using-the-generic-repository-pat ...
- PAT甲级 1001. A+B Format (20)
题目原文: Calculate a + b and output the sum in standard format -- that is, the digits must be separated ...
- kali linux下的arp攻击
这是我第一篇博客,写的不好请谅解 ____________________________(分割线)_______________________________ 在kali linux系统下自带工具 ...
- 记:MySQL 5.7.3.0 安装 全程截图
前言: 下一个班快讲MySQL数据库了,正好把服务器里面的MySQL卸了重装了一下. 截个图,作为笔记.也正好留给需要的朋友们. 目录: 下载软件 运行安装程序 安装程序欢迎界面 许可协议 查找更新 ...
- 2015微软MVP全球峰会见闻
2015.10.31-2015.11.8 一周的时间完成微软MVP全球峰会旅程,这一周在不断的倒时差,行程安排非常的紧张,还好和大家请假了没有更新微信公众号,今天开始继续更新微信公众号,开始新的旅程, ...
- 【腾讯Bugly干货分享】彻底弄懂 Http 缓存机制 - 基于缓存策略三要素分解法
本文来自于腾讯Bugly公众号(weixinBugly),未经作者同意,请勿转载,原文地址:https://mp.weixin.qq.com/s/qOMO0LIdA47j3RjhbCWUEQ 作者:李 ...
- 高性能的关键:Spring MVC的异步模式
我承认有些标题党了,不过话说这样其实也没错,关于“异步”处理的文章已经不少,代码例子也能找到很多,但我还是打算发表这篇我写了好长一段时间,却一直没发表的文章,以一个更简单的视角,把异步模式讲清楚. 什 ...
- (临时)C#中,exe 单例运行
Mutex mutex = new Mutex(false, ""); , false)) { MessageBox.Show("程序已经启动"); retur ...