public string AsSqlString() { var selectFragment = QueryAttributes .Select(attr => $"{attr.DeclaredIn.EntityName}.{attr.DataBaseColumn}") .Aggregate("", (s1, s2) => s1 == "" ? $"{s2}" : $"{s1}, {s2}"); var fromFragment = _from.AsFromFragment(); var whereFragment = _whereFilters.Select(w => w.AsSqlString()).Aggregate("", (w1, w2) => w1 == "" ? $"{w2}" :$"{w1} AND {w2}"); return($"SELECT {selectFragment} " + $"FROM {fromFragment} " + (whereFragment == "" ? "" : $"WHERE {whereFragment} ")); }
public string AsFromFragment() { var thisEntity = _thisEntity.AsFromFragment(); var thisAlias = _thisEntity.HasAlias() ? _thisEntity.GetAlias() : null; var joinedEntity = _joinedEntity.AsFromFragment(); var joinedAlias = _joinedEntity.HasAlias() ? _joinedEntity.GetAlias() : null; return($"({thisEntity}{(_thisEntity.HasAlias() ? $" as {thisAlias}" : "")}" + " INNER JOIN " + $"{joinedEntity} {(_joinedEntity.HasAlias() ? $" as {joinedAlias}" : "")}" + " ON " + $"{(_thisEntity.HasAlias() ? $"{thisAlias}." : "")}{_thisJoinAttr.DataBaseColumn} " + " = " + $"{(_joinedEntity.HasAlias() ? $"{joinedAlias}." : "")}{_joinedAttr.DataBaseColumn})" + $"{(HasAlias() ? $" as {GetAlias()}" : "")}"); }