public static string Get(FormattableString key) { return(string.Format(Localize(key.Format), key.GetArguments())); }
/// <summary> /// Append the given operation. /// </summary> /// <param name="operation">The operation to append.</param> public void AppendOperation(FormattableString operation) => AppendOperation(operation.Format, operation.GetArguments());
/// <summary> /// <para> /// Executes the given SQL against the database and returns the number of rows affected. /// </para> /// <para> /// Note that this method does not start a transaction. To use this method with /// a transaction, first call <see cref="BeginTransaction" /> or <see cref="M:UseTransaction" />. /// </para> /// <para> /// Note that the current <see cref="ExecutionStrategy" /> is not used by this method /// since the SQL may not be idempotent and does not run in a transaction. An <see cref="ExecutionStrategy" /> /// can be used explicitly, making sure to also use a transaction if the SQL is not /// idempotent. /// </para> /// <para> /// As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection /// attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional /// arguments. Any parameter values you supply will automatically be converted to a DbParameter: /// </para> /// <code> /// var userSuppliedSearchTerm = ".NET"; /// context.Database.ExecuteSqlInterpolatedAsync($"SELECT * FROM [dbo].[SearchBlogs]({userSuppliedSearchTerm})") /// </code> /// </summary> /// <param name="databaseFacade"> The <see cref="DatabaseFacade" /> for the context. </param> /// <param name="sql"> The interpolated string representing a SQL query with parameters. </param> /// <param name="cancellationToken"> A <see cref="CancellationToken" /> to observe while waiting for the task to complete. </param> /// <returns> /// A task that represents the asynchronous operation. The task result is the number of rows affected. /// </returns> public static Task <int> ExecuteSqlInterpolatedAsync( [NotNull] this DatabaseFacade databaseFacade, [NotNull] FormattableString sql, CancellationToken cancellationToken = default) => ExecuteSqlRawAsync(databaseFacade, sql.Format, sql.GetArguments(), cancellationToken);
public OperationException(FormattableString message, Exception innerException, OperationContext context) : base(message.Format, innerException) { MessageArguments = message.GetArguments(); Context = context; }
/// <summary> /// <para> /// Executes the given SQL against the database and returns the number of rows affected. /// </para> /// <para> /// Note that this method does not start a transaction. To use this method with /// a transaction, first call <see cref="BeginTransaction" /> or <see cref="UseTransaction" />. /// </para> /// <para> /// Note that the current <see cref="ExecutionStrategy" /> is not used by this method /// since the SQL may not be idempotent and does not run in a transaction. An ExecutionStrategy /// can be used explicitly, making sure to also use a transaction if the SQL is not /// idempotent. /// </para> /// <para> /// As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection /// attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional /// arguments. Any parameter values you supply will automatically be converted to a DbParameter - /// <code>context.Database.ExecuteInterpolatedSql($"SELECT * FROM [dbo].[SearchBlogs]({userSuppliedSearchTerm})")</code>. /// </para> /// </summary> /// <param name="databaseFacade"> The <see cref="DatabaseFacade" /> for the context. </param> /// <param name="sql"> The interpolated string representing a SQL query with parameters. </param> /// <returns> The number of rows affected. </returns> public static int ExecuteInterpolatedSql( [NotNull] this DatabaseFacade databaseFacade, [NotNull] FormattableString sql) => ExecuteRawSql(databaseFacade, sql.Format, sql.GetArguments());
/// <summary> /// Parses an interpolated-string SQL statement into a injection-safe statement (with parameters as @p0, @p1, etc) and a dictionary of parameter values. /// </summary> /// <param name="query"></param> public InterpolatedStatementParser(FormattableString query) : this(query.Format, query.GetArguments()) { }
public static IEnumerable <T> ExecuteQueryInterpolated <T>(this DatabaseFacade databaseFacade, FormattableString sql) => ExecuteQueryRaw <T>(databaseFacade, sql.Format, sql.GetArguments());
/// <inheritdoc /> public bool Any(FormattableString whereCondition) => Any(whereCondition, whereCondition.GetArguments());
public static RelationalDataReader ExecuteReaderInterpolated(this DatabaseFacade databaseFacade, FormattableString sql) => ExecuteReaderRaw(databaseFacade, sql.Format, sql.GetArguments());
public static Task <RelationalDataReader> ExecuteReaderInterpolatedAsync(this DatabaseFacade databaseFacade, FormattableString sql, CancellationToken cancelToken = default) => ExecuteReaderRawAsync(databaseFacade, sql.Format, sql.GetArguments(), cancelToken);
public GameString(FormattableString formattableString) { Literals = Regex.Split(formattableString.Format, @"{\d+}"); Variables = formattableString.GetArguments(); }
public ColorString Append(FormattableString formatString) { return(AppendFormat(formatString.Format, formatString.GetArguments())); }
public JoinableString(FormattableString formattableString) { _format = formattableString.Format; _arguments = formattableString.GetArguments(); }
/// <inheritdoc /> public IFilteredQuery <T> Where(FormattableString whereCondition) => Where(whereCondition, whereCondition.GetArguments());
public static IAsyncEnumerable <T> ExecuteQueryInterpolatedAsync <T>(this DatabaseFacade databaseFacade, FormattableString sql, CancellationToken cancelToken = default) => ExecuteQueryRawAsync <T>(databaseFacade, sql.Format, sql.GetArguments(), cancelToken);
/// <inheritdoc /> public T FirstOrDefault(FormattableString whereCondition) => FirstOrDefault(whereCondition, whereCondition.GetArguments());
public static T ExecuteScalarInterpolated <T>(this DatabaseFacade databaseFacade, FormattableString sql) => ExecuteScalarRaw <T>(databaseFacade, sql.Format, sql.GetArguments());
/// <inheritdoc/> public IQueryBase <T> Sql(FormattableString sql) => Sql(sql, sql.GetArguments());
public static Task <T> ExecuteScalarInterpolatedAsync <T>(this DatabaseFacade databaseFacade, FormattableString sql, CancellationToken cancelToken = default) => ExecuteScalarRawAsync <T>(databaseFacade, sql.Format, sql.GetArguments(), cancelToken);
public static int ExecuteSqlCommand( [NotNull] this DatabaseFacade databaseFacade, [NotNull] FormattableString sql) => ExecuteSqlCommand(databaseFacade, sql.Format, sql.GetArguments());
public virtual FormattableString NormalizeDelimetersInInterpolatedString(FormattableString sql) => new TestFormattableString(NormalizeDelimetersInRawString(sql.Format), sql.GetArguments());
public static FormattableString FormatConcat(FormattableString first, FormattableString second) { object?[] newArguments = first.GetArguments().Concat(second.GetArguments()).ToArray(); return(FormattableStringFactory.Create(first.Format + second.Format, newArguments)); }
static void M1(FormattableString s) => Console.WriteLine($"format: {s.Format}, args: {string.Join(", ", s.GetArguments())}");
/// <summary> /// <para> /// Executes the given SQL against the database and returns the number of rows affected. /// </para> /// <para> /// Note that this method does not start a transaction. To use this method with /// a transaction, first call <see cref="BeginTransaction" /> or <see cref="M:UseTransaction" />. /// </para> /// <para> /// Note that the current <see cref="ExecutionStrategy" /> is not used by this method /// since the SQL may not be idempotent and does not run in a transaction. An <see cref="ExecutionStrategy" /> /// can be used explicitly, making sure to also use a transaction if the SQL is not /// idempotent. /// </para> /// <para> /// As with any API that accepts SQL it is important to parameterize any user input to protect against a SQL injection /// attack. You can include parameter place holders in the SQL query string and then supply parameter values as additional /// arguments. Any parameter values you supply will automatically be converted to a DbParameter: /// </para> /// <code> /// var userSuppliedSearchTerm = ".NET"; /// context.Database.ExecuteSqlInterpolated($"UPDATE Blogs SET Rank = 50 WHERE Name = {userSuppliedSearchTerm})"); /// </code> /// </summary> /// <param name="databaseFacade"> The <see cref="DatabaseFacade" /> for the context. </param> /// <param name="sql"> The interpolated string representing a SQL query with parameters. </param> /// <returns> The number of rows affected. </returns> public static int ExecuteSqlInterpolated( this DatabaseFacade databaseFacade, FormattableString sql) => ExecuteSqlRaw(databaseFacade, sql.Format, sql.GetArguments() !);
public void WriteError(Exception exception, FormattableString message) { _logger.Error(exception, message.Format, message.GetArguments()); }