private void AppendTableFilter(SqlFilterItem item)
        {
            BindingFlags flag       = BindingFlags.Instance | BindingFlags.NonPublic;
            Type         type       = item.GetType();
            PropertyInfo field      = type.GetProperty("exp", flag);
            Type         ChildType  = type.GetProperty("type", flag).GetValue(item, null) as Type;
            var          entityInfo = this.Context.EntityMaintenance.GetEntityInfo(ChildType);
            var          exp        = field.GetValue(item, null) as Expression;
            var          isMain     = ChildType == this.EntityType;
            var          isSingle   = IsSingle();
            var          itName     = (exp as LambdaExpression).Parameters[0].Name;

            itName = this.Builder.GetTranslationColumnName(itName) + ".";
            var isEasyJoin = this.EasyJoinInfos.Count > 0;

            string sql = "";

            if (isSingle)
            {
                if (ChildType != this.EntityType && isSingle)
                {
                    return;
                }
                sql = GetSql(exp, isSingle);
            }
            else if (isMain)
            {
                if (TableShortName == null)
                {
                    return;
                }
                var shortName = this.Builder.GetTranslationColumnName(TableShortName) + ".";
                sql = GetSql(exp, isSingle);
                sql = sql.Replace(itName, shortName);
            }
            else if (isEasyJoin)
            {
                var easyInfo = EasyJoinInfos.FirstOrDefault(it =>
                                                            it.Value.Equals(entityInfo.DbTableName, StringComparison.CurrentCultureIgnoreCase) ||
                                                            it.Value.Equals(entityInfo.EntityName, StringComparison.CurrentCultureIgnoreCase));
                if (easyInfo.Key == null)
                {
                    return;
                }
                var shortName = this.Builder.GetTranslationColumnName(easyInfo.Key.Trim()) + ".";
                sql = GetSql(exp, isSingle);
                sql = sql.Replace(itName, shortName);
            }
            else
            {
                var easyInfo = JoinQueryInfos.FirstOrDefault(it =>
                                                             it.TableName.Equals(entityInfo.DbTableName, StringComparison.CurrentCultureIgnoreCase) ||
                                                             it.TableName.Equals(entityInfo.EntityName, StringComparison.CurrentCultureIgnoreCase));
                if (easyInfo == null)
                {
                    return;
                }
                var shortName = this.Builder.GetTranslationColumnName(easyInfo.ShortName.Trim()) + ".";
                sql = GetSql(exp, isSingle);
                sql = sql.Replace(itName, shortName);
            }
            if (item.IsJoinQuery == false || isMain || isSingle || isEasyJoin)
            {
                WhereInfos.Add(sql);
            }
            else
            {
                foreach (var joinInfo in this.JoinQueryInfos)
                {
                    if (joinInfo.TableName.EqualCase(entityInfo.EntityName) || joinInfo.TableName.EqualCase(entityInfo.DbTableName))
                    {
                        if (sql.StartsWith(" WHERE "))
                        {
                            sql = Regex.Replace(sql, $"^ WHERE ", " AND ");
                        }
                        joinInfo.JoinWhere = joinInfo.JoinWhere + sql;
                    }
                }
            }
        }
Exemple #2
0
        private void AppendTableFilter(SqlFilterItem item)
        {
            BindingFlags flag       = BindingFlags.Instance | BindingFlags.NonPublic;
            Type         type       = item.GetType();
            PropertyInfo field      = type.GetProperty("exp", flag);
            Type         ChildType  = type.GetProperty("type", flag).GetValue(item, null) as Type;
            var          entityInfo = this.Context.EntityMaintenance.GetEntityInfo(ChildType);
            var          exp        = field.GetValue(item, null) as Expression;
            var          isMain     = ChildType == this.EntityType;
            var          isSingle   = IsSingle();
            var          expValue   = GetExpressionValue(exp, isSingle ? ResolveExpressType.WhereSingle : ResolveExpressType.WhereMultiple);
            var          sql        = expValue.GetResultString();
            var          itName     = (exp as LambdaExpression).Parameters[0].Name;

            itName = this.Builder.GetTranslationColumnName(itName) + ".";
            var isEasyJoin = this.EasyJoinInfos.Count > 0;

            if (WhereInfos.Count == 0)
            {
                sql = (" WHERE " + sql);
            }
            else
            {
                sql = (" AND " + sql);
            }
            if (isSingle)
            {
                if (ChildType != this.EntityType)
                {
                    return;
                }
            }
            else if (isMain)
            {
                var shortName = this.Builder.GetTranslationColumnName(TableShortName) + ".";
                sql = sql.Replace(itName, shortName);
            }
            else if (isEasyJoin)
            {
                var easyInfo = EasyJoinInfos.FirstOrDefault(it =>
                                                            it.Value.Equals(entityInfo.DbTableName, StringComparison.CurrentCultureIgnoreCase) ||
                                                            it.Value.Equals(entityInfo.EntityName, StringComparison.CurrentCultureIgnoreCase));
                if (easyInfo.Key == null)
                {
                    return;
                }
                var shortName = this.Builder.GetTranslationColumnName(easyInfo.Key.Trim()) + ".";
                sql = sql.Replace(itName, shortName);
            }
            else
            {
                var easyInfo = JoinQueryInfos.FirstOrDefault(it =>
                                                             it.TableName.Equals(entityInfo.DbTableName, StringComparison.CurrentCultureIgnoreCase) ||
                                                             it.TableName.Equals(entityInfo.EntityName, StringComparison.CurrentCultureIgnoreCase));
                if (easyInfo == null)
                {
                    return;
                }
                var shortName = this.Builder.GetTranslationColumnName(easyInfo.ShortName.Trim()) + ".";
                sql = sql.Replace(itName, shortName);
            }
            WhereInfos.Add(sql);
        }