public CustomSqlServerMigrationGeneratorTests() { _dependenciesMock = new(); _annotationProviderMock = new(Strict); _renderer = new SqlServerRenderer(); _sut = new(null, _annotationProviderMock.Object); }
/// <summary> /// Builds the query /// </summary> /// <param name="whereClause">The WHERE conditions</param> /// <param name="maxResults">The number of results to return</param> /// <returns>The constructed SQL query</returns> private string BuildQuery(WhereClause whereClause, int maxResults) { SelectQuery query = new SelectQuery(); AcmaSchemaAttribute objectIdAttribute = ActiveConfig.DB.GetAttribute("objectId"); FromTerm objectBaseTable = objectIdAttribute.DBTable; query.Columns.Add(new SelectColumn("*", objectBaseTable)); query.Distinct = true; query.FromClause.BaseTable = objectBaseTable; foreach (FromTerm term in this.attributeTables) { query.FromClause.Join(JoinType.Left, objectBaseTable, term, new JoinCondition("objectId", "objectId")); } if (maxResults > 0) { query.Top = maxResults; } //if (this.parameters.Count == 0) //{ // return null; //} // Prevents returning the querying object as a search result if (Guid.Empty != this.SourceObjectId) { string param = this.AddParameter(this.SourceObjectId); query.WherePhrase.Terms.Add(WhereTerm.CreateCompare(SqlExpression.Field(objectIdAttribute.Name, objectIdAttribute.DBTable), SqlExpression.Parameter(param), CompareOperator.NotEqual)); } if (this.OrderByTerms != null) { query.OrderByTerms.AddRange(this.OrderByTerms); } query.WherePhrase.SubClauses.Add(whereClause); SqlServerRenderer renderer = new SqlServerRenderer(); return(renderer.RenderSelect(query)); }
public CustomSqlServerMigrationGenerator([NotNull] MigrationsSqlGeneratorDependencies dependencies, [NotNull] IMigrationsAnnotationProvider migrationsAnnotations) : base(dependencies, migrationsAnnotations) #endif { _renderer = new SqlServerRenderer(); }