Пример #1
0
 public EntityModel(EntityMap map)
 {
     _map = map;
     _queryPlan = BuildQueryPlan();
 }
Пример #2
0
        private QueryPlan BuildQueryPlan()
        {
            var plan = new QueryPlan();
            int count = 0;

            var tableAlias = "t" + count.ToString();
            if (string.IsNullOrEmpty(_map.ViewName))
            {
                plan.TableName = _map.TableName;
            }
            else
            {
                plan.TableName = _map.ViewName;
            }
            plan.TableAlias = tableAlias;

            var idName = tableAlias + "." + _map.Id.ColumnName;
            var idAlias = tableAlias + "_" + _map.Id.ColumnName;
            plan.AddId(_map.Id.MemberName, idName, idAlias, _map.Id.Accessors);

            foreach (var propertyItem in _map.Properties)
            {
                var columnName = tableAlias + "." + propertyItem.ColumnName;
                var columnAlias = tableAlias + "_" + propertyItem.ColumnName;
                plan.AddColumn(propertyItem.MemberName, columnName, columnAlias, propertyItem.Accessors);
            }

            foreach (var lookupItem in _map.Joins)
            {
                count++;
                var lookupAlias = "t" + count.ToString();

                var leftColumnName = tableAlias + "." + lookupItem.ParentColumn;
                var rightColumnName = lookupAlias + "." + lookupItem.ChildColumn;
                plan.AddJoin(lookupItem.TableName, lookupAlias, leftColumnName, rightColumnName, JoinType.LeftOuter);

                foreach (var propertyItem in lookupItem.Properties)
                {
                    var columnName = lookupAlias + "." + propertyItem.ColumnName;
                    var columnAlias = lookupAlias + "_" + propertyItem.ColumnName;
                    plan.AddColumn(propertyItem.MemberName, columnName, columnAlias, propertyItem.Accessors);
                }
            }

            return plan;
        }