예제 #1
0
 public ISqlElement GetUnionCondition(QueryEntityProperty property, QueryEntity entity)
 {
     if (property.mapping.UnionLayout == null)
     {
         return(null);
     }
     return(entity.unionCondition ?? (entity.unionCondition = CreateUnionCondition(property, entity)));
 }
예제 #2
0
        private ISqlElement CreateUnionCondition(QueryEntityProperty property, QueryEntity nestedEntity)
        {
            var typeColumnName = property.mapping.UnionLayout.TypeColumnName;

            if (string.IsNullOrEmpty(typeColumnName))
            {
                const string messageFormat = "type column is not defined for [{0}.{1}]";
                throw new InvalidOperationException(string.Format(messageFormat,
                                                                  property.referer.mapping.QueryTableName, property.mapping.PropertyName));
            }
            if (!nestedEntity.mapping.Index.HasValue)
            {
                const string messageFormat = "invalid table name [{0}], table name must contain index";
                throw new InvalidOperationException(string.Format(messageFormat,
                                                                  nestedEntity.mapping.DbTableName));
            }
            var tableIndexColumnName = property.mapping.UnionLayout.TableIndexColumnName;

            if (string.IsNullOrEmpty(tableIndexColumnName))
            {
                const string messageFormat = "tableIndex column is not defined for [{0}.{1}]";
                throw new InvalidOperationException(string.Format(messageFormat,
                                                                  property.referer.mapping.QueryTableName, property.mapping.PropertyName));
            }
            return(new AndExpression
            {
                Left = new EqualityExpression
                {
                    Left = new ColumnReferenceExpression
                    {
                        Name = typeColumnName,
                        Table = GetTableDeclaration(property.referer)
                    },
                    Right = new LiteralExpression
                    {
                        Value = configurationItemReferenceType,
                        SqlType = SqlType.ByteArray
                    }
                },
                Right = new EqualityExpression
                {
                    Left = new ColumnReferenceExpression
                    {
                        Name = tableIndexColumnName,
                        Table = GetTableDeclaration(property.referer)
                    },
                    Right = new LiteralExpression
                    {
                        Value = nestedEntity.mapping.Index,
                        SqlType = SqlType.ByteArray
                    }
                }
            });
        }
예제 #3
0
        public QueryEntity CreateQueryEntity(QueryEntityProperty referer, string queryName)
        {
            var tableMapping = mappingSource.ResolveTableOrNull(queryName);

            if (tableMapping == null)
            {
                const string messageFormat = "can't find table mapping for [{0}]";
                throw new InvalidOperationException(string.Format(messageFormat, queryName));
            }
            return(new QueryEntity(tableMapping, referer));
        }
예제 #4
0
        public QueryEntityProperty GetOrCreatePropertyIfExists(QueryEntity queryEntity, string name)
        {
            foreach (var f in queryEntity.properties)
            {
                if (f.mapping.PropertyName.EqualsIgnoringCase(name))
                {
                    return(f);
                }
            }
            PropertyMapping propertyMapping;

            if (!queryEntity.mapping.TryGetProperty(name, out propertyMapping))
            {
                return(null);
            }
            var property = new QueryEntityProperty(queryEntity, propertyMapping);

            if (propertyMapping.SingleLayout != null)
            {
                if (name.EqualsIgnoringCase(PropertyNames.id))
                {
                    if (queryEntity.mapping.Type == TableType.TableSection)
                    {
                        var nestedTableName = queryEntity.mapping.QueryTableName;
                        nestedTableName = TableMapping.GetMainQueryNameByTableSectionQueryName(nestedTableName);
                        AddQueryEntity(property, nestedTableName);
                    }
                    else
                    {
                        property.nestedEntities.Add(queryEntity);
                    }
                }
                else
                {
                    var nestedTableName = propertyMapping.SingleLayout.NestedTableName;
                    if (!string.IsNullOrEmpty(nestedTableName))
                    {
                        AddQueryEntity(property, nestedTableName);
                    }
                }
            }
            else
            {
                foreach (var t in propertyMapping.UnionLayout.NestedTables)
                {
                    AddQueryEntity(property, t);
                }
            }
            queryEntity.properties.Add(property);
            return(property);
        }
예제 #5
0
 private ColumnReferenceExpression GetPropertyReference(QueryEntityProperty property, SelectClause selectClause)
 {
     if (property.referer.mapping.IsEnum())
     {
         var enumMappingsJoinClause = queryEntityAccessor.CreateEnumMappingsJoinClause(property.referer);
         selectClause.JoinClauses.Add(enumMappingsJoinClause);
         return(new ColumnReferenceExpression
         {
             Name = "enumValueName",
             Table = (TableDeclarationClause)enumMappingsJoinClause.Source
         });
     }
     return(new ColumnReferenceExpression
     {
         Name = property.GetDbColumnName(),
         Table = queryEntityAccessor.GetTableDeclaration(property.referer)
     });
 }
예제 #6
0
 public QueryEntity CreateQueryEntity(QueryEntityProperty referer, string queryName)
 {
     return(queryEntityRegistry.CreateQueryEntity(referer, queryName));
 }
예제 #7
0
        private void AddQueryEntity(QueryEntityProperty referer, string tableName)
        {
            var queryEntity = queryEntityRegistry.CreateQueryEntity(referer, tableName);

            referer.nestedEntities.Add(queryEntity);
        }
예제 #8
0
 public QueryEntity(TableMapping mapping, QueryEntityProperty referer)
 {
     this.mapping = mapping;
     this.referer = referer;
 }