当前位置:   article > 正文

Sql Sugar 基本增删改查_sugarsql

sugarsql

1 按照《Sql sugar生成实体类》生成实体类

2 新建控制台项目,通过nuget安装SqlSugar

 3 将上面生成的实体类拷贝到项目

4  修改代码

  1. using Entitys;
  2. using SqlSugar;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace SqlSugarTest
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
  15. {
  16. ConnectionString = "server=.;database=ZAS.WGT.Common;uid=sa;pwd=Server2012",//连接符字串
  17. DbType = DbType.SqlServer, //数据库类型
  18. IsAutoCloseConnection = true //不设成true要手动close
  19. });
  20. db.Aop.OnLogExecuting = (sql, pars) =>
  21. {
  22. Console.WriteLine(sql);
  23. };
  24. //查询
  25. var list = db.Queryable<UserInfo>().ToList();
  26. //插入
  27. db.Insertable<UserInfo>(new UserInfo() { UserName = "zhangsan", Password = "zhangsan", Role = 2 }).ExecuteCommand();
  28. //更新
  29. db.Updateable(new UserInfo() { Id = 4, UserName="dxm", Role=2, Password="mypass"}).ExecuteCommand();
  30. //删除
  31. db.Deleteable<UserInfo>().Where(it => it.Id == 3).ExecuteCommand();
  32. }
  33. }
  34. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/134890
推荐阅读
相关标签
  

闽ICP备14008679号