Beispiel #1
0
        public SQL Create(Expression <Func <T, bool> > Where, Analysis analysis)
        {
            var _SQL = new SQL();

            //修正Where 表达式树结构
            var _Table     = Parser.GetTableInfo(typeof(T));
            var _TableName = _Table.TableName;

            if (Where != null && Where.Parameters[0].Name != _Table.TableName)
            {
                var _Set_Parameter = Expression.Parameter(typeof(T), _TableName);
                Where = Expression.Lambda <Func <T, bool> >(Where.Body, _Set_Parameter);
            }

            _TableName = DbSettings.KeywordHandle(_TableName);

            _SQL.Code.AppendFormat("DELETE FROM {0} WHERE 1=1 ", _TableName);

            if (Where != null)
            {
                _SQL.IsAlias = false;

                analysis.CreateWhere(Where, _SQL);

                _SQL.Code.AppendFormat("AND {0}", _SQL.Code_Where);
            }

            _SQL.Code.Append(";");

            return(_SQL);
        }
Beispiel #2
0
        public void Create(SQL _Sql, LambdaExpression _LambdaExpression, EJoinType _EJoinType, Analysis analysis)
        {
            if (_LambdaExpression.Body is BinaryExpression)
            {
                var body = (_LambdaExpression.Body as BinaryExpression);

                var _Parameters = _LambdaExpression.Parameters;

                var _Parameter = _Parameters[_Parameters.Count - 1];

                var _Alias = DbSettings.KeywordHandle(_Parameter.Name);

                var _TabName = DbSettings.KeywordHandle(_Parameter.Type.Name);

                _Sql.Code_Join.AppendFormat(" {0} {1} AS {2} ON ", _EJoinType.ToString().Replace("_", " "), _TabName, _Alias);

                var _New_Sql = new SQL();
                _New_Sql.Parameter = _Sql.Parameter;

                analysis.CreateWhere(_LambdaExpression, _New_Sql);

                _Sql.Code_Join.Append(_New_Sql.Code_Where);

                _Sql.Parameter = _New_Sql.Parameter;

                _Sql.Alias[_Alias] = _TabName;
            }
        }
Beispiel #3
0
        public SQL Create(MemberInitExpression _MemberInitExpression, Expression <Func <T, bool> > Where, Analysis analysis)
        {
            var           _SQL = new SQL();
            List <string> _Set = new List <string>();

            //修正Where 表达式树结构
            var _Table     = Parser.GetTableInfo(typeof(T));
            var _TableName = _Table.TableName;

            if (Where != null && Where.Parameters[0].Name != _Table.TableName)
            {
                var _Set_Parameter = Expression.Parameter(typeof(T), _TableName);
                Where = Expression.Lambda <Func <T, bool> >(Where.Body, _Set_Parameter);
            }

            _TableName = DbSettings.KeywordHandle(_TableName);

            foreach (MemberAssignment item in _MemberInitExpression.Bindings)
            {
                //检测有无忽略字段
                if (_Table.Fields.FirstOrDefault(w => w.IsIgnore && w.FieldName == item.Member.Name) != null)
                {
                    continue;
                }

                var _Name = item.Member.Name;

                if (_Table.KeyFieldName == _Name && _Table.KeyFieldInfo.IsIdentity)//如果主键自增
                {
                    continue;
                }

                var _Count = _SQL.Parameter.Count;

                var _Key = "@" + _Name + "_" + _Count;

                _Set.Add(_Name + "=" + _Key);

                var _Val = Parser.Eval(item.Expression);

                _SQL.Parameter.Add(new DbParam()
                {
                    ParameterName = _Key, Value = _Val
                });
            }

            _SQL.Code.AppendFormat("UPDATE {0} SET {1} WHERE 1=1 ", _TableName, string.Join(",", _Set));

            if (Where != null)
            {
                _SQL.IsAlias = false;

                analysis.CreateWhere(Where, _SQL);

                _SQL.Code.AppendFormat("AND {0}", _SQL.Code_Where);
            }

            _SQL.Code.Append(";");

            return(_SQL);
        }