赞
踩
1 按照《Sql sugar生成实体类》生成实体类
2 新建控制台项目,通过nuget安装SqlSugar
3 将上面生成的实体类拷贝到项目
4 修改代码
- using Entitys;
- using SqlSugar;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
-
- namespace SqlSugarTest
- {
- class Program
- {
- static void Main(string[] args)
- {
- SqlSugarClient db = new SqlSugarClient(new ConnectionConfig()
- {
- ConnectionString = "server=.;database=ZAS.WGT.Common;uid=sa;pwd=Server2012",//连接符字串
- DbType = DbType.SqlServer, //数据库类型
- IsAutoCloseConnection = true //不设成true要手动close
- });
-
- db.Aop.OnLogExecuting = (sql, pars) =>
- {
- Console.WriteLine(sql);
- };
-
- //查询
- var list = db.Queryable<UserInfo>().ToList();
-
- //插入
- db.Insertable<UserInfo>(new UserInfo() { UserName = "zhangsan", Password = "zhangsan", Role = 2 }).ExecuteCommand();
-
- //更新
- db.Updateable(new UserInfo() { Id = 4, UserName="dxm", Role=2, Password="mypass"}).ExecuteCommand();
-
- //删除
- db.Deleteable<UserInfo>().Where(it => it.Id == 3).ExecuteCommand();
-
-
- }
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。