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 };