mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +08:00
Update exp tosql
This commit is contained in:
parent
586a42d5c8
commit
5541979963
@ -27,8 +27,102 @@ namespace OrmTest
|
||||
Db.Updateable<BoolTest>(x).ReSetValue(it => it.BoolValue == true).ExecuteCommand();
|
||||
Db.Updateable<BoolTest>(x).ReSetValue(it => it.BoolValue == !it.BoolValue).ExecuteCommand();
|
||||
Db.Updateable<BoolTest>(x).UpdateColumns(it =>new { it.BoolValue }) .ExecuteCommand();
|
||||
|
||||
|
||||
|
||||
SaveDiary saveDiary = new SaveDiary();
|
||||
saveDiary.ID = 2;
|
||||
saveDiary.TypeID = 10;
|
||||
saveDiary.TypeName = "类型100";
|
||||
saveDiary.Title = "标题1000";
|
||||
saveDiary.Content = "内容";
|
||||
saveDiary.Time = DateTime.Now;
|
||||
saveDiary.IsRemind = false;//无论传false/true 最终执行的结果都是以true执行的
|
||||
|
||||
var sql = Db.Updateable<Diary>().SetColumns(it => new Diary()
|
||||
{
|
||||
IsRemind = saveDiary.IsRemind,
|
||||
}).Where(it => it.ID == saveDiary.ID).ToSql();
|
||||
UValidate.Check(sql.Key, @"UPDATE [Diary] SET
|
||||
[IsRemind] = @Const1 WHERE ( [ID] = @ID2 )", "Updateable");
|
||||
|
||||
}
|
||||
}
|
||||
public class SaveDiary
|
||||
{
|
||||
public int ID { get; set; }
|
||||
public int TypeID { get; set; }
|
||||
public string TypeName { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Content { get; set; }
|
||||
public DateTime? Time { get; set; }
|
||||
public bool IsRemind { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 日记表
|
||||
/// </summary>
|
||||
[SugarTable("Diary")]
|
||||
public class Diary
|
||||
{
|
||||
[SugarColumn(IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int ID { get; set; }
|
||||
/// <summary>
|
||||
/// 用户ID
|
||||
/// </summary>
|
||||
public int? UserID { get; set; }
|
||||
/// <summary>
|
||||
/// 日记类型ID
|
||||
/// </summary>
|
||||
public int TypeID { get; set; }
|
||||
/// <summary>
|
||||
/// 日记类型名称
|
||||
/// </summary>
|
||||
public string TypeName { get; set; }
|
||||
/// <summary>
|
||||
/// 标题
|
||||
/// </summary>
|
||||
public string Title { get; set; }
|
||||
/// <summary>
|
||||
/// 内容
|
||||
/// </summary>
|
||||
public string Content { get; set; }
|
||||
/// <summary>
|
||||
/// 时间
|
||||
/// </summary>
|
||||
public DateTime? Time { get; set; }
|
||||
/// <summary>
|
||||
/// 是否提醒
|
||||
/// </summary>
|
||||
public bool? IsRemind { get; set; }
|
||||
/// <summary>
|
||||
/// 封面图
|
||||
/// </summary>
|
||||
public string Cover { get; set; }
|
||||
/// <summary>
|
||||
/// 是否为系统日记 1:系统日记 0:用户日记
|
||||
/// </summary>
|
||||
public bool? IsSystem { get; set; }
|
||||
/// <summary>
|
||||
/// 权重(排序)
|
||||
/// </summary>
|
||||
public int? Sequence { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string IP { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public DateTime? CreateTime { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public DateTime? UpdateTime { get; set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool? IsDelete { get; set; }
|
||||
}
|
||||
|
||||
public class BoolTest
|
||||
{
|
||||
|
@ -491,6 +491,11 @@ namespace SqlSugar
|
||||
Check.ThrowNotSupportedException(item.GetType().Name);
|
||||
}
|
||||
}
|
||||
protected static bool IsConvert(Expression item)
|
||||
{
|
||||
return item is UnaryExpression && item.NodeType == ExpressionType.Convert;
|
||||
}
|
||||
|
||||
protected static bool IsNotMember(Expression item)
|
||||
{
|
||||
return item is UnaryExpression &&
|
||||
|
@ -110,6 +110,10 @@ namespace SqlSugar
|
||||
else if (IsConst(item))
|
||||
{
|
||||
base.Expression = item;
|
||||
if (IsConvert(item))
|
||||
{
|
||||
base.Expression = (base.Expression as UnaryExpression).Operand;
|
||||
}
|
||||
base.Start();
|
||||
string parameterName = this.Context.SqlParameterKeyWord + ExpressionConst.Const + this.Context.ParameterIndex;
|
||||
parameter.Context.Result.Append(base.Context.GetEqString(memberName, parameterName));
|
||||
@ -163,7 +167,6 @@ namespace SqlSugar
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsConst(Expression item)
|
||||
{
|
||||
return item is UnaryExpression || item.NodeType == ExpressionType.Constant || (item is MemberExpression) && ((MemberExpression)item).Expression.NodeType == ExpressionType.Constant;
|
||||
|
Loading…
Reference in New Issue
Block a user