public class UserManager : DbContext<User>{}
UserManager userdb = new UserManager(); //创建对象
var user = userdb.GetFirst(u => u.UserName == userName && u.Password == pwd);
//继承,可以使用父类方法GetFirst() public class DbContext<T> where T : class, new()
{
public SqlSugarClient Db;//用来处理事务多表查询和复杂的操作
public DbContext()
{
Db = new SqlSugarClient(new ConnectionConfig()
{ … });
}
public virtual T GetFirst(Expression<Func<T, bool>> whereExpression)
{
return Db.Queryable<T>().First(whereExpression);
}
} SqlSugarClient Db对象下面的方法 public class SqlSugarClient : ISqlSugarClient, IDisposable, Itenant
{
public SqlSugarProvider Context => GetContext();
//public ISugarQueryable<T> Queryable<T>();
public ISugarQueryable<T> Queryable<T>()
{
return Context.Queryable<T>(); //返回的对象的类是继承于ISugarQueryable<T>接口
//所以可以继续点first方法 Db.Queryable<T>().First(whereExpression);
}
private SqlSugarProvider GetContext()
{
if (IsSameThreadAndShard())
{
return SameThreadAndShard();
}
if (IsNoSameThreadAndShard())
{
return NoSameThreadAndShard();
}
if (IsSynchronization())
{
return Synchronization();
}
return NoSameThread();
}
} //接口 ; 继承并实现first方法
public interface ISugarQueryable<T>
{
T First(Expression<Func<T, bool>> expression);
}
// \.nuget\packages\sqlsugarcore\5.0.0.1\lib\netstandard2.0\SqlSugar.dll
cehsimodelManager abc = new cehsimodelManager();
abc.GetFirst(u => u.btnname == "admin" && u.btnid == "123465"); //c#
//sql
exec sp_executesql N'SELECT * FROM (SELECT [btnname],[btnid],ROW_NUMBER() OVER(ORDER BY GETDATE() ) AS RowIndex
FROM [cehsimodel] WHERE (( [btnname] = @btnname0 ) AND ( [btnid] = @btnid1 ))) T WHERE RowIndex BETWEEN 1 AND 1',N'@btnname0 nvarchar(4000),@btnid1 nvarchar(4000)',@btnname0=N'admin',@btnid1=N''
--[cehsimodel] 类的名称要和表名称一致

public class cehsimodelManager : DbContext<cehsimodel>
{}

//类

public class cehsimodel
{
public string btnname { get; set; }

public string btnid { get; set; }
}

          List<Leave> list1;
if (user_s[].ReadLeave==null|| user_s[].ReadLeave.Trim()==string.Empty) {
user_s[].ReadLeave = "";
}
 if (pid == ) //查询未读取的
{
list1 = Leavedb.GetPageList(d => !user_s[].ReadLeave.Contains(d.LeaveId.ToString()), pageinfo,
d => d.CreateTime, OrderByType.Asc);
}
else //读取的
{
list1 = Leavedb.GetPageList(d => user_s[].ReadLeave.Contains(d.LeaveId.ToString()), pageinfo,
d => d.CreateTime, OrderByType.Asc);
}

//sql语句查询

  //if (pid == 1) //查询未读取的
//{
// sql = string.Format("select * from Leave where LeaveId not in ({0}) ", user_s[0].ReadLeave); // list1 = Leavedb.Db.SqlQueryable<Leave>(sql).ToList().OrderByDescending(n=>n.CreateTime).ToList(); //时间降序
//}
//else //读取的
//{
// sql = string.Format("select * from Leave where LeaveId in ({0}) ", user_s[0].ReadLeave);
// list1 = Leavedb.Db.SqlQueryable<Leave>(sql).ToList().OrderByDescending(n => n.CreateTime).ToList();
//}

--执行sql 语句

var t = exec_sql_list("UPDATE [dbo].[ColumnInfo]  SET  [IsDel] = 'false'    ");

return Db.SqlQueryable<ColumnInfo>(sql).ToList();

--转换的sql语句
SELECT t.* FROM ( UPDATE [dbo].[ColumnInfo] SET [IsDel] = 'false' ) t

--执行更新集合

UPDATE S 

SET S.[IsDel]=T.[IsDel],S.[ColumnTitleContent]=T.[ColumnTitleContent],S.[Sort]=T.[Sort],S.[Remark]=T.[Remark],S.[CreateUserName]=T.[CreateUserName],S.[CreateRealName]=T.[CreateRealName],S.[CreateTime]=T.[CreateTime],S.[ModifyUserName]=T.[ModifyUserName],S.[ModifyRealName]=T.[ModifyRealName],S.[ModifyTime]=T.[ModifyTime] FROM [ColumnInfo] S    INNER JOIN             (

 SELECT  AS [IsDel],N'' AS [ColumnInfoId],N'测试' AS [ColumnTitleContent],N'' AS [Sort],N'测试' AS [Remark],N'sysadmin' AS [CreateUserName],N'超级管理员' AS [CreateRealName],'2019-09-09 18:09:34.500' AS [CreateTime],NULL AS [ModifyUserName],NULL AS [ModifyRealName],NULL AS [ModifyTime]
UNION ALL
SELECT AS [IsDel],N'' AS [ColumnInfoId],N'2010测试' AS [ColumnTitleContent],N'' AS [Sort],N'策划is' AS [Remark],N'sysadmin' AS [CreateUserName],N'超级管理员' AS [CreateRealName],'2019-09-10 08:17:01.013' AS [CreateTime],NULL AS [ModifyUserName],NULL AS [ModifyRealName],NULL AS [ModifyTime]
UNION ALL
SELECT AS [IsDel],N'' AS [ColumnInfoId],N'' AS [ColumnTitleContent],N'' AS [Sort],N'' AS [Remark],N'sysadmin' AS [CreateUserName],N'超级管理员' AS [CreateRealName],'2019-09-10 08:17:25.087' AS [CreateTime],NULL AS [ModifyUserName],NULL AS [ModifyRealName],NULL AS [ModifyTime]
UNION ALL
SELECT AS [IsDel],N'' AS [ColumnInfoId],N'' AS [ColumnTitleContent],N'' AS [Sort],N'' AS [Remark],N'sysadmin' AS [CreateUserName],N'超级管理员' AS [CreateRealName],'2019-09-10 08:17:31.547' AS [CreateTime],NULL AS [ModifyUserName],NULL AS [ModifyRealName],NULL AS [ModifyTime]
UNION ALL
SELECT AS [IsDel],N'' AS [ColumnInfoId],N'' AS [ColumnTitleContent],N'' AS [Sort],N'' AS [Remark],N'sysadmin' AS [CreateUserName],N'超级管理员' AS [CreateRealName],'2019-09-10 08:17:37.523' AS [CreateTime],NULL AS [ModifyUserName],NULL AS [ModifyRealName],NULL AS [ModifyTime]
UNION ALL
SELECT AS [IsDel],N'' AS [ColumnInfoId],N'' AS [ColumnTitleContent],N'' AS [Sort],N'' AS [Remark],N'sysadmin' AS [CreateUserName],N'超级管理员' AS [CreateRealName],'2019-09-10 08:17:44.583' AS [CreateTime],NULL AS [ModifyUserName],NULL AS [ModifyRealName],NULL AS [ModifyTime]
UNION ALL
SELECT AS [IsDel],N'' AS [ColumnInfoId],N'' AS [ColumnTitleContent],N'' AS [Sort],N'' AS [Remark],N'sysadmin' AS [CreateUserName],N'超级管理员' AS [CreateRealName],'2019-09-10 08:17:53.443' AS [CreateTime],N'sysadmin' AS [ModifyUserName],N'超级管理员' AS [ModifyRealName],'2019-09-10 09:35:37.440' AS [ModifyTime]
UNION ALL
SELECT AS [IsDel],N'' AS [ColumnInfoId],N'' AS [ColumnTitleContent],N'' AS [Sort],N'' AS [Remark],N'sysadmin' AS [CreateUserName],N'超级管理员' AS [CreateRealName],'2019-09-10 08:18:00.900' AS [CreateTime],NULL AS [ModifyUserName],NULL AS [ModifyRealName],NULL AS [ModifyTime]
UNION ALL
SELECT AS [IsDel],N'' AS [ColumnInfoId],N'' AS [ColumnTitleContent],N'' AS [Sort],N'' AS [Remark],N'sysadmin' AS [CreateUserName],N'超级管理员' AS [CreateRealName],'2019-09-10 08:18:07.283' AS [CreateTime],N'sysadmin' AS [ModifyUserName],N'超级管理员' AS [ModifyRealName],'2019-09-10 09:31:48.427' AS [ModifyTime] ) T ON S.[ColumnInfoId]=T.[ColumnInfoId]

执行单个

exec sp_executesql N'UPDATE [ColumnInfo]  SET
[IsDel]=@IsDel,[ColumnTitleContent]=@ColumnTitleContent,[Sort]=@Sort,[Remark]=@Remark,[CreateUserName]=@CreateUserName,[CreateRealName]=@CreateRealName,[CreateTime]=@CreateTime,[ModifyUserName]=@ModifyUserName,[ModifyRealName]=@ModifyRealName,[ModifyTime]=@ModifyTime WHERE [ColumnInfoId]=@ColumnInfoId',N'@IsDel bit,@ColumnInfoId int,@ColumnTitleContent nvarchar(),@Sort int,@Remark nvarchar(),@CreateUserName nvarchar(),@CreateRealName nvarchar(),@CreateTime datetime,@ModifyUserName nvarchar(),@ModifyRealName nvarchar(),@ModifyTime datetime',@IsDel=1,@ColumnInfoId=9,@ColumnTitleContent=N'',@Sort=1,@Remark=N'',@CreateUserName=N'sysadmin',@CreateRealName=N'超级管理员',@CreateTime='-- ::44.583',@ModifyUserName=N'sysadmin',@ModifyRealName=N'超级管理员',@ModifyTime='-- ::20.240'

C# SqlSugarClient分析一点的更多相关文章

  1. note——《Tableau商业分析一点通》

    为了更好地发掘各领域的数据价值,且能对数据进行精确分析及可视化,掌握资料的脉动,做出正确的决策 人们需要一种工具:能够快速灵活地连接和整合数据,提供简单的方式实现从不同的角度去观察研究数据,计算和展示 ...

  2. 分析一点python源代码

    偶然看了一下python的部分源代码,感觉python的作者写的代码真心很美,简洁美观,学习之. 举几个例子抛砖引玉一下: def removedirs(name): ""&quo ...

  3. 死磕以太坊源码分析之EVM如何调用ABI编码的外部方法

    死磕以太坊源码分析之EVM如何调用ABI编码的外部方法 配合以下代码进行阅读:https://github.com/blockchainGuide/ 写文不易,给个小关注,有什么问题可以指出,便于大家 ...

  4. 银行HR:寒门再难出贵子

    银行HR:寒门再难出贵子来源:金融行业网 2013 年 8 月 6 日 来源:天涯社区 作者:永乐大帝二世 本文是一位银行的HR写的,他工作了10年,接待了一群到银行实习的实习生,然后观察他们发生的好 ...

  5. B树在数据库索引中的应用剖析

    引言 关于数据库索引,google一个oracle index,mysql index总 有大量的结果,其中很多的使用方法推荐,**索引之n条经典建议云云.笔者认为,较之借鉴,在搞清楚了自己的需求的基 ...

  6. android事件传递机制以及onInterceptTouchEvent()和onTouchEvent()详解二之小秘与领导的故事

    总结的不是很好,自己也有点看不懂,正好现在用到了,研究了一个,再次总结,方便大家查看 总则: 1.onInterceptTouchEvent中有个Intercept,这是什么意思呢?她叫拦截,你大概知 ...

  7. RunTime 入门

    原文链接:http://www.jianshu.com/p/59992507f875 这是一篇浅显实用 易记 易理解的关于runtime的解读. Runtime 中的方法主要以五个单词开头——clas ...

  8. jsp和html的区别

    html是超文本标记语言,只要有浏览器,就可以显示出来了. jsp是java server page就是在java服务器端的页面,需要通过jdk的编译才可以显示在客户端的浏览器上. 不仅如此,jsp还 ...

  9. <Android 基础(三十四)> TabLayout 从头到脚

    1. 简介 1.TabLayout给我们提供的是一排横向的标签页 2.#newTab()这个方法来创建新的标签页,然后用过#setText()和#setIcon方法分别修改标签页的文本和图标,创建完成 ...

随机推荐

  1. Opencv之LBP特征(算法)

    LBP(Local Binary Pattern),即局部二进制模式,对一个像素点以半径r画一个圈,在圈上取K个点(一般为8),这K个点的值(像素值大于中心点为1,否则为0)组成K位二进制数.此即局部 ...

  2. lua基础学习(六)

    一.lua协同程序coroutine 1.什么是协同(coroutine)?Lua 协同程序(coroutine)与线程比较类似:拥有独立的堆栈,独立的局部变量,独立的指令指针,同时又与其它协同程序共 ...

  3. mysql——单表查询——聚合函数——概念

    使用聚合函数查询 group by关键字通常和聚合函数一起使用 .count()函数 count()函数用来统计记录的条数 举例:使用count()函数统计employee表的记录数 select c ...

  4. Picnic Planning POJ - 1639(度限制生成树)

    解题报告   题意理解 给定一张N个点,M个边的无向图,求出无向图的一颗最小生成树,但是我们要求一号节点的入度不可以超过给定的整数S 也就是一个最小生成树,要求它的一号节点,最多只能和S个节点相连. ...

  5. js 判断图片是否存在

    有的时候  虽然图片的路径是正确的 但是有可能由于某些原因  导致图裂了 或者网络加载失败   那这样的应该怎么判断呢? 如下: function isHasImg(pathImg){ var Img ...

  6. mysql元数据以及一些常用命令

    所谓mysql元数据就是一些初始的东西,例如数据库的列表,数据表列表,查询影响的行数等等,还有就是mysql的服务器的一些信息,例如版本信息等. select version(): 获取mysql服务 ...

  7. javaSql面试题(10题)

    有如下四张表: 学生表Student(stuId,stuName,stuAge,stuSex): 课程表Course(courseId,courseName,teacherId): 成绩表Scores ...

  8. GDAL支持中文路径和Shp文件中文属性写入

    在使用GDAL的过程中,为了支持中文,比需手动进行中文路径的设置,同时特别是在对Shp的属性进行中文输入的时候,都必须进行必要的设定. 为了支持中文路径,在注册了驱动之后,加上第三句就可以了.必须设置 ...

  9. RabbitMQ延迟队列插件安装

    RabbitMQ延迟队列插件安装 一.下载插件 下载地址:https://www.rabbitmq.com/community-plugins.html 二.把下载的插件放到指定位置 下载的文件为zi ...

  10. 测试 windows 发布日志

    <script>alert("hellow world")</script>