protected override SqlCaluse Where(BinaryExpression exp, SqlCaluse sqlCaluse) { ExpressionVisit.Where(exp.Left, sqlCaluse); var insertIndex = sqlCaluse.Length; ExpressionVisit.Where(exp.Right, sqlCaluse); var endIndex = sqlCaluse.Length; var b = endIndex - insertIndex == 5 && sqlCaluse.EndWith("null"); OperatorParser(exp.NodeType, insertIndex, sqlCaluse.Sql, b); return(sqlCaluse); }
protected override SqlCaluse Update(MemberInitExpression exp, SqlCaluse sqlCaluse) { var bindings = exp.Bindings; foreach (MemberBinding binding in bindings) { if (binding is MemberAssignment memberExp) { var name = binding.Member.GetAttribute <ColumnNameAttribute>()?.Name; var value = Expression.Lambda(memberExp.Expression).Compile().DynamicInvoke(); sqlCaluse += $" {name ?? binding.Member.Name} = "; sqlCaluse += sqlCaluse.AddDbParameter(value); sqlCaluse += ",\n"; } } if (sqlCaluse.EndWith(",\n")) { sqlCaluse.Sql.Remove(sqlCaluse.Sql.Length - 2, 2); } return(sqlCaluse); }
protected override SqlCaluse Update(NewExpression exp, SqlCaluse sqlCaluse) { for (int i = 0; i < exp.Members.Count; i++) { var member = exp.Members[i]; var arg = exp.Arguments[i]; //var name = member.GetAttribute<ColumnNameAttribute>()?.Name ?? member.Name; var func = Expression.Lambda(arg).Compile(); var value = func.DynamicInvoke(); if (value == null || value == DBNull.Value) { continue; } sqlCaluse += $" {member.Name} = "; sqlCaluse += sqlCaluse.AddDbParameter(value); sqlCaluse += ",\n"; } if (sqlCaluse.EndWith(",\n")) { sqlCaluse.Sql.Remove(sqlCaluse.Sql.Length - 2, 2); } return(sqlCaluse); }
protected override SqlCaluse Update(MemberExpression exp, SqlCaluse sqlCaluse) { var e = Expression.Lambda(exp).Compile().DynamicInvoke(); var eType = e.GetType(); var props = eType.GetProperties(); for (int i = 0; i < props.Length; i++) { var p = props[i]; var value = p.GetValue(e, null); if (value == null || value == default || value == DBNull.Value) { continue; } if (sqlCaluse.IgnoreFields.Contains(p.Name)) { continue; } if (p.GetAttribute <IgnoreAttribute>() != null) { continue; } if (p.GetAttribute <PrimaryKeyAttribute>() != null) { continue; } var name = p.GetAttribute <ColumnNameAttribute>()?.Name; sqlCaluse += $" {name ?? p.Name} = "; sqlCaluse += sqlCaluse.AddDbParameter(value); sqlCaluse += ",\n"; } if (sqlCaluse.EndWith(",\n")) { sqlCaluse.Sql.Remove(sqlCaluse.Sql.Length - 2, 2); } return(sqlCaluse); }