c# 常用

SQL参数

集合
list = list.GroupBy(a =>a.keyCode).Select(item => item.First()).ToList();//去重
list = list.Concat(listOld).ToList();//合并
List<string> 转 List<int>
var listOfInts = listOfStrings.Select<string,int>(q =>Convert.ToInt32(q));
换行符分行读取
List<string> striparr = originalTxt.Split(new string[] { "\r\n" }, StringSplitOptions.None).ToList();

SqlSugar

修改指定列传实体
 wq.Db.Updateable(s).UpdateColumns(a => new { a.getTime,a.shortUrlTitle 
}).ExecuteCommand();
um.UpdateColumns(u, c => new { c.loginErrorCount, c.lastLoginTime });
单列修改
 wq.Db.Updateable<WXTable>().SetColumns(a => a.listCount == a.listCount + 1).Where(a => a.id == w.id).ExecuteCommand();
im.UpdateColumns(p, a => new { a.payState, a.remark });
多列修改
im.Db.Updateable<Invoice>().SetColumns(a =>new Invoice() { refund= Convert.ToInt32(refundType),refundDay=DateTime.Now }).Where(a => a.userId ==
                 user.userId && idlist.Contains(a.id)).ExecuteCommand();
修改列不传实体
wxt.WXTableDb.Update(it => new WXTable()
                {
                    shortUrlTitle = shortUrlTitle.Text.Trim(),
                    random = random.Checked,
                    password = password.Text.Trim(),
                    remark = remark.Text.Trim(),
                    blcokReAdd = blcokReAdd.Checked,
                    topText = topText.Text.Trim(),
                    bottomText = bottomText.Text.Trim(),
                }, it => it.id == s.id);
修改用in的另外一种形式
im.Db.Updateable<Invoice>().SetColumns(a => a.refund == Convert.ToInt32(refundType)).Where(a => a.userId ==
                user.userId && idlist.Contains(a.id)).ExecuteCommand();

int除不完直接进位
int c = (int)Math.Ceiling((double)2 / (double)2);

正则式
[\u4E00-\u9FFF]中文

JSON
JObject res = JObject.Parse(reslut);
            res["retmsg"]
 JObject staff = new JObject();
            staff.Add(new JProperty("Name", "Jack"));

判断子key并获取值
 if (res["words_result"]["CommodityName"].Count() > 0)
            {
                Newtonsoft.Json.Linq.JToken jtoken = res["words_result"]["CommodityName"];
                for (int i = 0; i < jtoken.Count(); i++)
                {
                    if (jtoken[i].Value<string>("word") != null)
                    {
                        inv.information = jtoken["word"].ToString() + ",";
                    }
                }
            }


选择部分
var list = from s in reslut.list select new { s.id, s.typeId, s.invoiceId, s.information, s.invoiceDay, s.conpany, s.seller, s.total, s.refund, s.remark, s.printCount, s.pdfFile, s.invoiceRemark };
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值