using (var db = SugarDao.GetInstance()) { List<School> dataList = db.Sqlable() .From(, ) .Join(, , , , JoinType.INNER) .Join(, , , , JoinType.LEFT) .Where() .Where()//可以多个WHERE .OrderBy() .SelectToList<School>(, new { id = 1 }); //多表分页 List<School> dataPageList = db.Sqlable() .From(, ) .Join(, , , , JoinType.INNER) .Join(, , , , JoinType.LEFT) .Where() .SelectToPageList<School>(, , 1, 10); //多表分页WHERE加子查询 List<School> dataPageList2 = db.Sqlable() .From(, ) .Join(, , , , JoinType.INNER) .Join(, , , , JoinType.LEFT) .Where() .SelectToPageList<School>(, , 1, 10); list1 = db.Sqlable().From(, ).Join(, , , , JoinType.INNER).SelectToDynamic(, new { id = 1 }); , ).Join(, , , , JoinType.INNER).SelectToJson(, new { id = 1 }); , ).Join(, , , , JoinType.INNER).SelectToDataTable(, new { id = 1 }); list4 = db.Sqlable().From(, ).Join(, , , , JoinType.INNER).SelectToPageDynamic(, , 1, 10, new { id = 1 }); , ).Join(, , , , JoinType.INNER).SelectToPageTable(, , 1, 10, new { id = 1 }); , ).Join(, , , , JoinType.INNER).SelectToPageDynamic(, , 1, 10, new { id = 1 }); //--------拼接-----// Sqlable sable = db.Sqlable().From<Student>().Join<School>(, , , JoinType.INNER); ; int id = 1; if (!string.IsNullOrEmpty(name)) { sable = sable.Where(); } if (!string.IsNullOrEmpty(name)) { sable = sable.Where(); } if (id > 0) { sable = sable.Where();//where加子查询 } var pars = new { id = id, name = name }; int pageCount = sable.Count(pars); , , 1, 20, pars); }
4、更新
//指定列更新 db.Update<School>(}, it => it.id == 14); //只更新name列 db.Update<School, , areaId = 2 }, 11, 23, 12); db.Update<School, }, , }); db.Update<School>(}, it => it.id == 100); dic = new Dictionary<string, string>(); dic.Add(, ); dic.Add(, ); db.Update<School, int>(dic, 13); //整个实体更新 db.Update(, AreaId = 1 }); db.Update<School>(, AreaId = 2 }, it => it.id == 18); db.Update<School>( }); //设置不更新列 db.DisableUpdateColumns = };//设置CreateTime不更新 TestUpdateColumns updObj = new TestUpdateColumns() { VGUID = Guid.Parse(), Name = , Name2 = , IdentityField = 0, CreateTime = null }; //CreateTime将不会被更新 db.Update(updObj); //以前实现这种更新需要用指定列的方式实现,现在就简单多了。 updateResult = db.UpdateRange(GetUpdateList()); updateResult2 = db.SqlBulkReplace(GetUpdateList2());
5、删除和状态删除