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. 交换机安全学习笔记 第四章 VLAN

      Trunk 口  思科称为:native VLAN  华为称为:PVID   说白了就是Trunk端口本身所属的VLAN,因为,Trunk端口要"透传"多个VLAN的流量,其本 ...

  2. Spring(二)--Spring入门案例

    Spring入门案例 1.需要的实体类 2.需要的接口和实现类 3.需要的service和实现类 /** * service层的作用 * 在不改变dao层代码的前提下,增加业务逻辑操作 */ publ ...

  3. numpy将数组保存为文件

    保存单个数组 np.save和np.load是读写磁盘数组数据的两个主要函数.默认情况下,数组是以未压缩的原始二进制格式保存在扩展名为.npy的文件中的: 如果文件路径末尾没有扩展名.npy,则该扩展 ...

  4. js知识点——2之navigator

    navigator(领航者) 1.appCodeName(返回浏览器的代码名) var x= navigator; document.write("CodeName:"+x.app ...

  5. static修饰的成员与非static修饰类的成员的区别

    ① 格式 : 1> static修饰的,称为静态成员,非static修饰的,称为非静态成员. ② 内存位置: 1>static修饰的,在方法区的静态区中,非static修饰的,在堆中的对象 ...

  6. 初探CSS - 5 创建

    CSS 创建 当读到一个样式表时,浏览器会根据它来格式化 HTML 文档. 如何插入样式表 插入样式表的方法有三种: 外部样式表(External style sheet) 内部样式表(Interna ...

  7. Linux系统nmtui/nmcli绑定双网卡为team

    今天给大家带来图形化界面网络配置工具—nmtui的使用方法,可以省去敲命令的繁琐,较少误操作,结果更加直观. 小知识: nmtui:Network Manager Text User Interfac ...

  8. Listview.Finditem()函数用法

    查找LISTVIEW控件中指定的字符串.   Private Sub ListView2_Click() On Error GoTo ONERROR Dim strFindMe As String   ...

  9. Codeforces 965 枚举轮数贪心分糖果 青蛙跳石头最大流=最小割思想 trie启发式合并

    A /*#include<cstring>#include<algorithm>#include<queue>#include<vector>#incl ...

  10. 线段树优化建图 || CF786B Legacy

    题面:786B - Legacy 代码: #include<cstdio> #include<cstring> #include<iostream> #includ ...