Exemplo n.º 1
0
        void PrepareSubqueryMappingDictonary()
        {
            foreach (var association in MetaData.AssociateProperties)
            {
                var associateMetaData = DataProviderMetaDataGenerator.Generate(association.AssociateType);

                var alias        = SqlCommandGenerator.SafeId($"{{0}}.{association.Name}_{associateMetaData.TableName}");
                var partialAlias = $"{{0}}.{association.Name}_";

                var template = $@"SELECT {alias}.{associateMetaData.IdColumnName}
                    FROM {associateMetaData.GetTableTemplate(SqlCommandGenerator).FormatWith(partialAlias)}
                    WHERE {alias}.{SqlCommandGenerator.SafeId(associateMetaData.IdColumnName)} = {SqlCommandGenerator.SafeId("{1}")}.{SqlCommandGenerator.SafeId(association.Name)}";

                SubqueryMapping.Add(
                    association.Name.WithSuffix(".*"),
                    template);
            }

            foreach (var baseClass in MetaData.BaseClassesInOrder)
            {
                foreach (var pair in baseClass.GetProvider(Cache, Access, SqlCommandGenerator).SubqueryMapping)
                {
                    if (SubqueryMapping.ContainsKey(pair.Key) && SubqueryMapping[pair.Key] != pair.Value)
                    {
                        throw new Exception("Multiple subqueries needed with the same key.");
                    }

                    SubqueryMapping[pair.Key] = pair.Value;
                }
            }
        }
Exemplo n.º 2
0
        public virtual string MapColumn(string propertyName)
        {
            if (ColumnMapping.TryGetValue(propertyName, out string result))
            {
                return(result);
            }

            return($"{MetaData.TableAlias}.{SqlCommandGenerator.SafeId(propertyName)}");
        }
Exemplo n.º 3
0
 public virtual string GenerateWhere(DatabaseQuery query) =>
 SqlCommandGenerator.GenerateWhere(query);
Exemplo n.º 4
0
 public virtual string GenerateSelectCommand(IDatabaseQuery iquery, string fields) =>
 SqlCommandGenerator.GenerateSelectCommand(iquery, GetTables(iquery.AliasPrefix), fields);
Exemplo n.º 5
0
 string GetSqlCommandColumn(IDataProviderMetaData medaData, string propertyName) =>
 $"{medaData.TableAlias}.{SqlCommandGenerator.SafeId(propertyName)}";