zoukankan      html  css  js  c++  java
  • Dapper的语法应用

    (1)返回某个整型或字符串类型的字段

    public string GetSupplierCodeById(int Id)
    { 
    using( var conn=DbFactory.CreateConnection())
    {
    var result = conn.Query<dynamic>(GetSupplierCodeByIdSql, new { Id = Id }).FirstOrDefault();
    return result.Code;
    }
    }
    /// 添加包装
            /// </summary>
            /// <param name="p"></param>
            public int AddPackSP(Pack p)
            {
                using (var conn = DbFactory.CreateConnection())
                {
                    //var result = conn.Execute(AddPackSPSql, p);
                    var result = conn.Query<dynamic>(AddPackSPSql, p).FirstOrDefault();
                    return result != null ? Convert.ToInt32(result.PackId) : 0;
                }
            }

    (2)返回一个对象

     public Material GetMaterialByCode(string code)
    {
          using (DbConnection conn = DbFactory.CreateConnection())
          {
              var result = conn.Query<Material>(GetMaterialByCodeSql,
              new { Code = code }).FirstOrDefault();
               return result;
           }
     }

    (3)返回一个集合

       返回一条数据:

       public IList<Supplier> GetValidSupplier(int employeeId)
            {
                using (var conn = DbFactory.CreateConnection())
                {
                    var result = conn.Query<Supplier>(GetValidSupplierByEIdSql,
                      new { EmployeeId = employeeId }).ToList();
                    return result;
                }
            }

    返回多条数据:

     public IList<Supplier> GetSupplierList(int supplierType)
            {
                using (var conn = DbFactory.CreateConnection())
                {
                    var result = conn.QueryMultiple(GetSupplierListBySupplierTypeSql,
                        new { SupplierType = supplierType }).Read<Supplier>().ToList();
                    return result;
                }
            }

    (4)返回bool类型(判断是否增删改成功或是否被引用等)

     public bool IsUsed(int supplierId)
            {
                using (var conn = DbFactory.CreateConnection())
                {
                    var result = conn.QueryMultiple(IsUsedSql,
                        new { SupplierId = supplierId }).Read<int>().Single() > 0;
                    return result;
                }
            }
     public bool DeleteMaterial(int materialId)
            {
                using (DbConnection conn = DbFactory.CreateConnection())
                {
                    bool result = conn.Execute(DeleteMaterialSql, new { Id = materialId }) > 0;
    
                    return result;
                }
            }

  • 相关阅读:
    CVE-2018-18778 mini_httpd任意文件读取漏洞
    libssh 服务端权限认证绕过漏洞(CVE-2018-10933)
    Apache SSI 远程命令执行漏洞
    Weblogic < 10.3.6 'wls-wsat' XMLDecoder 反序列化漏洞(CVE-2017-10271)
    PHP-FPM 远程代码执行漏洞(CVE-2019-11043)
    msfvenom各平台payload生成
    msfvenom绕过杀软之stage编码
    msfvenom payload的可持续化
    metasploit几个重要的监听参数
    msfvenom参数简介
  • 原文地址:https://www.cnblogs.com/abc8023/p/3843339.html
Copyright © 2011-2022 走看看