static void Main(string[] args)
{
ConnectionConfig connectionConfig = new ConnectionConfig()
{
DbType = DbType.SqlServer,
ConnectionString = "Server=.;Initial Catalog=Test;User ID=Test;Password=Test",
IsAutoCloseConnection = true
};
using (SqlSugarClient db = new SqlSugarClient(connectionConfig))
{
//调式代码 用来打印SQL
db.Aop.OnLogExecuting = (sql, pars) =>
{
Console.WriteLine(sql + "\r\n" + db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
};
//新增返回ID
var entity = db.Insertable<EmailEntity>(new EmailEntity()
{
EmailArr = "[email protected]",
EmailContent = "测试邮件,请忽略"
}).ExecuteReturnEntity();
//根据ID更新
db.Updateable<EmailEntity>(new EmailEntity()
{
Id = entity.Id,
EmailArr = "[email protected]",
EmailContent = "测试邮件,请忽略111"
}).UpdateColumns(it => new { it.EmailArr, it.EmailContent }).ExecuteCommandAsync();
//删除
db.Deleteable<EmailEntity>(new EmailEntity()
{
Id = entity.Id
}).ExecuteCommandAsync();
//按查询条件查询
string querParam = "测试";
var exp = Expressionable.Create<EmailEntity>();
exp.AndIF(!string.IsNullOrWhiteSpace(querParam), it => it.EmailContent.Contains(querParam));
//exp.OrIF(true, it => it.EmailContent.Contains(querParam));
db.Queryable<EmailEntity>().Where(exp.ToExpression()).ForEach(it =>
{
Console.WriteLine(it.EmailContent);
});
}
Console.ReadKey();
}
标签:EmailContent,C#,改查,db,querParam,exp,test,new,SqlSugar From: https://www.cnblogs.com/hauk0755/p/18454776