Example #1
0
 public static string CreatJoinSql(Join join, Func <string, ColumnInfo> createColumnInfo)
 {
     return(CreatJoinSql(join, join.JoinInfo.Member.ToDictionary(jc => jc.Key.Field, jc => jc.Value.Field), createColumnInfo));
 }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="columns"></param>
        /// <param name="root"></param>
        /// <returns></returns>
        protected static Dictionary <string, ColumnInfo> Create(IEnumerable <string> columns, ClassInfo root, Func <string, ColumnInfo> createColumnInfo, Func <string, ClassNode, ClassInfo> createClassInfo)
        {
            var result  = new Dictionary <string, ColumnInfo>();
            var joinDic = new Dictionary <string, Join>();

            foreach (var item in columns)
            {
                if (result.ContainsKey(item))
                {
                    continue;
                }
                var columnInfo = createColumnInfo(item);

                var temp = item;
                if (!item.Equals("count(0)", StringComparison.OrdinalIgnoreCase))
                {
                    var match = Regex.Match(item, @"(?'name'.+)\((?'property'.+)\)");
                    if (match.Success)
                    {
                        temp = match.Groups["property"].Value;
                        columnInfo._aggregateFunctionName = match.Groups["name"].Value;
                    }
                }

                var  array  = temp.Split('.');
                var  key    = string.Empty;
                var  host   = root;
                Join parent = null;
                for (int i = 0; i < array.Length;)
                {
                    var property = array[i];

                    var joinInfo = host.ClassNode.JoinList.FirstOrDefault(p => p.Name.Equals(property, System.StringComparison.OrdinalIgnoreCase));
                    if (joinInfo == null && host.ClassNode.BaseClassNode != null)
                    {
                        joinInfo = FindProperty(host.ClassNode.BaseClassNode, property);
                        if (joinInfo != null)
                        {
                            property = host.ClassNode.BaseClassNode.Name;
                            joinInfo = host.ClassNode.JoinList.FirstOrDefault(p => p.Name.Equals(property, System.StringComparison.OrdinalIgnoreCase));
                            i--;
                        }
                    }

                    if (joinInfo == null)                   //不是导航属性,就当它是普通属性
                    {
                        List <JoinPropertyNode> parents;
                        columnInfo._classInfo = host;
                        columnInfo._field     = property;

                        if (IsParentProperty(host.ClassNode, 0, property, out parents))                       //搞定继承的问题
                        {
                            parents.Reverse();
                            var last = AddJoin(joinDic, parent, host, parents[0].Name, parents, createClassInfo);
                            columnInfo._join = last;
                            //columnInfo._subAsName = host.AsName;
                            columnInfo._home      = host;
                            columnInfo._classInfo = last.Target;
                        }

                        break;
                    }

                    if (string.IsNullOrEmpty(key))
                    {
                        key = property;
                    }
                    else
                    {
                        key += "." + property;
                    }

                    if (!joinDic.ContainsKey(key))
                    {
                        var join = new Join(parent, host);
                        join.JoinInfo = joinInfo;
                        join.Target   = createClassInfo("J", joinInfo.Target);

                        host             = join.Target;
                        parent           = join;
                        columnInfo._join = join;

                        joinDic.Add(key, join);
                    }
                    else
                    {
                        var join = joinDic[key];

                        columnInfo._join = join;
                        parent           = join;
                        host             = join.Target;
                    }

                    i++;
                }

                if (columnInfo != null)
                {
                    result.Add(item, columnInfo);
                }
            }

            return(result);
        }