MyDAL

索引:

目录索引

SQL Debug 信息说明

一. 对 XConnection 对象 未开启 OpenDebug, 在 VS  状态下,将默认在 VS 窗口 打印出 参数化的 SQL 执行语句:

    新增:

1             var m1 = new BodyFitRecord
2             {
3                 Id = Guid.Parse("1fbd8a41-c75b-45c0-9186-016544284e2e"),
4                 CreatedOn = DateTime.Now,
5                 UserId = Guid.NewGuid(),
6                 BodyMeasureProperty = "{xxx:yyy,mmm:nnn}"
7             };
8 
9             var res1 = await Conn.CreateAsync(m1);

    以 MySQL 为例,生成 参数化 SQL ,在 VS 输出窗口 如下:

 

     删除:

1             var res2 = await Conn
2                 .Deleter<BodyFitRecord>()
3                 .Where(it => it.Id == Guid.Parse("1fbd8a41-c75b-45c0-9186-016544284e2e"))
4                 .DeleteAsync();

    以 MySQL 为例,生成 参数化 SQL ,在 VS 输出窗口 如下:

 

     修改:

 1  var pk1 = Guid.Parse("8f2cbb64-8356-4482-88ee-016558c05b2d");
 2 
 3  var model = new AlipayPaymentRecord();
 4  model.Description = "new desc";   // 修改 AlipayPaymentRecord 字段 Description 的值为: "new desc"
 5  model.PaymentUrl = "new url";  //  修改 AlipayPaymentRecord 字段 PaymentUrl 的值为: "new url"
 6 
 7  // 修改一条数据: AlipayPaymentRecord
 8  var res1 = await Conn.UpdateAsync<AlipayPaymentRecord>(it => it.Id == pk1, //where条件:it=>it.Id==pk1,可输入任意条件的表达式
 9  new
10  {
11      model.Description,    // 修改 AlipayPaymentRecord 字段 Description 的值
12      model.PaymentUrl    //  修改 AlipayPaymentRecord 字段 PaymentUrl 的值
13    });

    以 MySQL 为例,生成 参数化 SQL ,在 VS 输出窗口 如下:

     查询:

1             var res1 = await Conn
2                 .Queryer(out Agent agent, out AgentInventoryRecord record)
3                 .From(() => agent)
4                     .InnerJoin(() => record)
5                         .On(() => agent.Id == record.AgentId)
6                 .QueryPagingAsync(1, 10, () => agent.Name);

    以 MySQL 为例,生成 参数化 SQL ,在 VS 输出窗口 如下:

 

二. 对 XConnection 对象 开启 OpenDebug, 在 VS  状态下,将在 VS 窗口 打印出 非参数化的 SQL 执行语句:

     新增:

 1             var list = new List<AddressInfo>();
 2             for (var i = 0; i < 10; i++)
 3             {
 4                 if (i % 2 == 0)
 5                 {
 6                     list.Add(new AddressInfo
 7                     {
 8                         Id = Guid.NewGuid(),
 9                         CreatedOn = DateTime.Now,
10                         ContactName = "Name_" + i.ToString(),
11                         ContactPhone = "1800000000" + i.ToString(),
12                         DetailAddress = "Address_" + i.ToString(),
13                         IsDefault = true,   // f:bool c:bit(1)
14                         UserId = Guid.NewGuid()
15                     });
16                 }
17                 else
18                 {
19                     list.Add(new AddressInfo
20                     {
21                         Id = Guid.NewGuid(),
22                         CreatedOn = DateTime.Now,
23                         ContactName = "Name_" + i.ToString(),
24                         ContactPhone = "1800000000" + i.ToString(),
25                         DetailAddress = "Address_" + i.ToString(),
26                         IsDefault = false,   // f:bool c:bit(1)
27                         UserId = Guid.NewGuid()
28                     });
29                 }
30             }
31 
32             var res1 = await Conn2.OpenDebug().CreateBatchAsync(list);

    以 Sql Server 为例,生成 非参数化 SQL ,在 VS 输出窗口 如下:

    删除:

1             var res2 = await Conn.OpenDebug()
2                 .Deleter<Agent>()
3                 .Where(it => it.PathId == path)
4                 .Or(it => it.AgentLevel == (AgentLevel)level)
5                 .DeleteAsync();

    以 MySQL 为例,生成 非参数化 SQL ,在 VS 输出窗口 如下:

    修改:

1             // 多 字段 多 set 用法
2             var res1 = await Conn.OpenDebug()
3                 .Updater<BodyFitRecord>()  // 更新表 BodyFitRecord 
4                 .Set(it => it.CreatedOn, DateTime.Now)    //  设置字段 CreatedOn 值
5                 .Set(it => it.BodyMeasureProperty, "{xxx:yyy,mmm:nnn,zzz:aaa}")  //  设置字段 BodyMeasureProperty 值
6                 .Where(it => it.Id == m.Id)
7                 .UpdateAsync();

    以 MySQL 为例,生成 非参数化 SQL ,在 VS 输出窗口 如下: 

     查询:

1             var res5 = await Conn.OpenDebug()
2                 .Queryer(out Agent agent5, out AgentInventoryRecord record5)
3                 .From(() => agent5)
4                     .InnerJoin(() => record5)
5                         .On(() => agent5.Id == record5.AgentId)
6                 .Where(() => agent5.AgentLevel == AgentLevel.DistiAgent)    //  const  enum  ==
7                 .QueryListAsync<AgentInventoryRecord>();

    以 MySQL 为例,生成 非参数化 SQL ,在 VS 输出窗口 如下: 

三. 其它情况 说明:

  a.在 VS 状态下,无论你是否打开 .OpenDebug(),都不会在 窗口 输出 sql 语句

  b..OpenDebug() 方法 有一个 DebugEnum 可选枚举参数,默认输出到 VS 输出窗口,当指定 DebugEnum.Console 时,

    会输出到 控制台 窗口,这时 在控制台窗口 无论程序是 debug 还是 release 状态运行 都会打印出 非参数化 sql 语句。

                                         蒙

                                    2019-05-20 17:19 周一

原文地址:https://www.cnblogs.com/Meng-NET/p/10895268.html