Ejemplo n.º 1
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);
        }