Skip to content

Commit

Permalink
Rename FromRawSql to FromSqlRaw and related
Browse files Browse the repository at this point in the history
Fixes #15079
  • Loading branch information
ajcvickers committed Apr 1, 2019
1 parent bd2732b commit 140f4cf
Show file tree
Hide file tree
Showing 26 changed files with 379 additions and 379 deletions.
10 changes: 5 additions & 5 deletions benchmark/Shared.EFCore/Query/RawSqlQueryTests.cs
Expand Up @@ -37,7 +37,7 @@ public virtual void CreateContext()
{
if (!string.IsNullOrEmpty(StoredProcedureCreationScript))
{
ctx.Database.ExecuteRawSql(StoredProcedureCreationScript);
ctx.Database.ExecuteSqlRaw(StoredProcedureCreationScript);
}
});

Expand All @@ -59,7 +59,7 @@ public virtual void CleanupContext()
public virtual async Task SelectAll()
{
var query = _context.Products
.FromRawSql(@"SELECT * FROM ""Products""")
.FromSqlRaw(@"SELECT * FROM ""Products""")
.ApplyTracking(Tracking);

if (Async)
Expand All @@ -76,7 +76,7 @@ public virtual async Task SelectAll()
public virtual async Task SelectParameterized()
{
var query = _context.Products
.FromRawSql(@"SELECT * FROM ""Products"" WHERE ""CurrentPrice"" >= @p0 AND ""CurrentPrice"" <= @p1", 10, 14)
.FromSqlRaw(@"SELECT * FROM ""Products"" WHERE ""CurrentPrice"" >= @p0 AND ""CurrentPrice"" <= @p1", 10, 14)
.ApplyTracking(Tracking);

if (Async)
Expand All @@ -93,7 +93,7 @@ public virtual async Task SelectParameterized()
public virtual async Task SelectComposed()
{
var query = _context.Products
.FromRawSql(@"SELECT * FROM ""Products""")
.FromSqlRaw(@"SELECT * FROM ""Products""")
.ApplyTracking(Tracking)
.Where(p => p.CurrentPrice >= 10 && p.CurrentPrice <= 14)
.OrderBy(p => p.Name);
Expand All @@ -112,7 +112,7 @@ public virtual async Task SelectComposed()
public virtual async Task StoredProcedure()
{
var query = _context.Products
.FromRawSql(@"EXECUTE dbo.SearchProducts @p0, @p1", 10, 14)
.FromSqlRaw(@"EXECUTE dbo.SearchProducts @p0, @p1", 10, 14)
.ApplyTracking(Tracking);

if (Async)
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/RawSqlString.cs
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.EntityFrameworkCore
/// the regular and interpolated <see cref="RelationalQueryableExtensions.FromSql{TEntity}(IQueryable{TEntity},RawSqlString,object[])" />
/// and <see cref="RelationalDatabaseFacadeExtensions.ExecuteSqlCommand(Infrastructure.DatabaseFacade,RawSqlString,object[])" />
/// </summary>
[Obsolete("For the execution of SQL queries using plain strings, use FromRawSql, ExecuteRawSql, or ExecuteRawSqlAsync instead. For the execution of SQL queries using interpolated string syntax to create parameters, use FromInterpolatedSql, ExecuteInterpolatedSql, or ExecuteInterpolatedSqlAsync instead.")]
[Obsolete("For the execution of SQL queries using plain strings, use FromSqlRaw, ExecuteSqlRaw, or ExecuteSqlRawAsync instead. For the execution of SQL queries using interpolated string syntax to create parameters, use FromSqlInterpolated, ExecuteSqlInterpolated, or ExecuteSqlInterpolatedAsync instead.")]
public readonly struct RawSqlString
{
/// <summary>
Expand Down
62 changes: 31 additions & 31 deletions src/EFCore.Relational/RelationalDatabaseFacadeExtensions.cs

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions src/EFCore.Relational/RelationalQueryableExtensions.cs
Expand Up @@ -19,7 +19,7 @@ public static class RelationalQueryableExtensions
{
internal static readonly MethodInfo FromSqlMethodInfo
= typeof(RelationalQueryableExtensions)
.GetTypeInfo().GetDeclaredMethods(nameof(FromRawSql))
.GetTypeInfo().GetDeclaredMethods(nameof(FromSqlRaw))
.Single();

/// <summary>
Expand Down Expand Up @@ -53,7 +53,7 @@ public static class RelationalQueryableExtensions
/// <param name="parameters"> The values to be assigned to parameters. </param>
/// <returns> An <see cref="IQueryable{T}" /> representing the raw SQL query. </returns>
[StringFormatMethod("sql")]
[Obsolete("For returning objects from SQL queries using plain strings, use FromRawSql instead. For returning objects from SQL queries using interpolated string syntax to create parameters, use FromInterpolatedSql instead.")]
[Obsolete("For returning objects from SQL queries using plain strings, use FromSqlRaw instead. For returning objects from SQL queries using interpolated string syntax to create parameters, use FromSqlInterpolated instead.")]
public static IQueryable<TEntity> FromSql<TEntity>(
[NotNull] this IQueryable<TEntity> source,
[NotParameterized] RawSqlString sql,
Expand Down Expand Up @@ -94,7 +94,7 @@ public static class RelationalQueryableExtensions
/// </param>
/// <param name="sql"> The interpolated string representing a SQL query. </param>
/// <returns> An <see cref="IQueryable{T}" /> representing the interpolated string SQL query. </returns>
[Obsolete("For returning objects from SQL queries using plain strings, use FromRawSql instead. For returning objects from SQL queries using interpolated string syntax to create parameters, use FromInterpolatedSql instead.")]
[Obsolete("For returning objects from SQL queries using plain strings, use FromSqlRaw instead. For returning objects from SQL queries using interpolated string syntax to create parameters, use FromSqlInterpolated instead.")]
public static IQueryable<TEntity> FromSql<TEntity>(
[NotNull] this IQueryable<TEntity> source,
[NotNull] [NotParameterized] FormattableString sql)
Expand All @@ -119,19 +119,19 @@ public static class RelationalQueryableExtensions
/// </para>
/// <para>
/// If the database provider supports composing on the supplied SQL, you can compose on top of the raw SQL query using
/// LINQ operators - <code>context.Blogs.FromRawSql("SELECT * FROM dbo.Blogs").OrderBy(b => b.Name)</code>.
/// LINQ operators - <code>context.Blogs.FromSqlRaw("SELECT * FROM dbo.Blogs").OrderBy(b => b.Name)</code>.
/// </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.Blogs.FromRawSql("SELECT * FROM [dbo].[SearchBlogs]({0})", userSuppliedSearchTerm)</code>.
/// You can also consider using <see cref="FromInterpolatedSql{TEntity}(IQueryable{TEntity}, FormattableString)"/> to use interpolated string syntax to create parameters.
/// <code>context.Blogs.FromSqlRaw("SELECT * FROM [dbo].[SearchBlogs]({0})", userSuppliedSearchTerm)</code>.
/// You can also consider using <see cref="FromSqlInterpolated{TEntity}"/> to use interpolated string syntax to create parameters.
/// </para>
/// <para>
/// This overload also accepts DbParameter instances as parameter values. This allows you to use named
/// parameters in the SQL query string -
/// <code>context.Blogs.FromRawSql("SELECT * FROM [dbo].[SearchBlogs]({@searchTerm})", new SqlParameter("@searchTerm", userSuppliedSearchTerm))</code>
/// <code>context.Blogs.FromSqlRaw("SELECT * FROM [dbo].[SearchBlogs]({@searchTerm})", new SqlParameter("@searchTerm", userSuppliedSearchTerm))</code>
/// </para>
/// </summary>
/// <typeparam name="TEntity"> The type of the elements of <paramref name="source" />. </typeparam>
Expand All @@ -142,7 +142,7 @@ public static class RelationalQueryableExtensions
/// <param name="parameters"> The values to be assigned to parameters. </param>
/// <returns> An <see cref="IQueryable{T}" /> representing the raw SQL query. </returns>
[StringFormatMethod("sql")]
public static IQueryable<TEntity> FromRawSql<TEntity>(
public static IQueryable<TEntity> FromSqlRaw<TEntity>(
[NotNull] this IQueryable<TEntity> source,
[NotParameterized] string sql,
[NotNull] params object[] parameters)
Expand All @@ -167,37 +167,37 @@ public static class RelationalQueryableExtensions
/// </para>
/// <para>
/// If the database provider supports composing on the supplied SQL, you can compose on top of the raw SQL query using
/// LINQ operators - <code>context.Blogs.FromInterpolatedSql($"SELECT * FROM dbo.Blogs").OrderBy(b => b.Name)</code>.
/// LINQ operators - <code>context.Blogs.FromSqlInterpolated($"SELECT * FROM dbo.Blogs").OrderBy(b => b.Name)</code>.
/// </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 interpolated parameter place holders in the SQL query string. Any interpolated parameter values
/// you supply will automatically be converted to a DbParameter -
/// <code>context.Blogs.FromInterpolatedSql($"SELECT * FROM [dbo].[SearchBlogs]({userSuppliedSearchTerm})")</code>.
/// <code>context.Blogs.FromSqlInterpolated($"SELECT * FROM [dbo].[SearchBlogs]({userSuppliedSearchTerm})")</code>.
/// </para>
/// </summary>
/// <typeparam name="TEntity"> The type of the elements of <paramref name="source" />. </typeparam>
/// <param name="source">
/// An <see cref="IQueryable{T}" /> to use as the base of the interpolated string SQL query (typically a <see cref="DbSet{TEntity}" />).
/// </param>
/// <param name="interpolatedSql"> The interpolated string representing a SQL query with parameters. </param>
/// <param name="sql"> The interpolated string representing a SQL query with parameters. </param>
/// <returns> An <see cref="IQueryable{T}" /> representing the interpolated string SQL query. </returns>
public static IQueryable<TEntity> FromInterpolatedSql<TEntity>(
public static IQueryable<TEntity> FromSqlInterpolated<TEntity>(
[NotNull] this IQueryable<TEntity> source,
[NotNull] [NotParameterized] FormattableString interpolatedSql)
[NotNull] [NotParameterized] FormattableString sql)
where TEntity : class
{
Check.NotNull(source, nameof(source));
Check.NotNull(interpolatedSql, nameof(interpolatedSql));
Check.NotEmpty(interpolatedSql.Format, nameof(source));
Check.NotNull(sql, nameof(sql));
Check.NotEmpty(sql.Format, nameof(source));

return source.Provider.CreateQuery<TEntity>(
Expression.Call(
null,
FromSqlMethodInfo.MakeGenericMethod(typeof(TEntity)),
source.Expression,
Expression.Constant(interpolatedSql.Format),
Expression.Constant(interpolatedSql.GetArguments())));
Expression.Constant(sql.Format),
Expression.Constant(sql.GetArguments())));
}
}
}
Expand Up @@ -25,15 +25,15 @@ public virtual Task FromSql_logs_concurrent_access_nonasync()
c =>
{
// ReSharper disable once UnusedVariable
var result = c.Products.FromRawSql("select * from products").ToList();
var result = c.Products.FromSqlRaw("select * from products").ToList();
return Task.FromResult(false);
});
}

[Fact]
public virtual Task FromSql_logs_concurrent_access_async()
{
return ConcurrencyDetectorTest(c => c.Products.FromRawSql("select * from products").ToListAsync());
return ConcurrencyDetectorTest(c => c.Products.FromSqlRaw("select * from products").ToListAsync());
}
}
}

0 comments on commit 140f4cf

Please sign in to comment.