Sakura.AspNetCore.Extensions/Sakura.EntityFrameworkCore.FromSqlExtensions/DbContextFromSqlExtensions.cs
/// <summary>
///     Executing a SQL statement and retrieve the result set directly frm the specified <see cref="DbContext" />.
/// </summary>
/// <typeparam name="T">The type of the item in the result set.</typeparam>
/// <param name="dbContext">The <see cref="DbContext" /> instance.</param>
/// <param name="sql">The SQL statement to be executing.</param>
/// <param name="parameters">Arguments provided along with the parameterized <paramref name="sql" />.</param>
/// <returns>A <see cref="IQueryable{T}" /> instance which can be used for retrieving the result or making a further query.</returns>
Executing a SQL statement and retrieve the result set directly frm the specified .
Executing a SQL statement and retrieve the result set directly frm the specified .
[PublicAPI]
		public static IQueryable<T> FromSql<T>(this DbContext dbContext, RawSqlString sql, params object[] parameters)
		{
			if (dbContext == null) throw new ArgumentNullException(nameof(dbContext));
			dbContext.TryAddQueryType<T>();
			var queryProvider = dbContext.GetDependencies().QueryProvider;
			var querySource = new EntityQueryable<T>(queryProvider);
			var expression = Expression.Call(null, FromSqlMethod.MakeGenericMethod(typeof(T)), querySource.Expression,
				Expression.Constant(sql), Expression.Constant(parameters));
			return queryProvider.CreateQuery<T>(expression);
		}
[ PublicAPI ] public static IQueryable < T > FromSql < T > ( this DbContext dbContext , RawSqlString sql , params object [ ] parameters ) { if ( dbContext == null ) throw new ArgumentNullException ( nameof ( dbContext ) ) ; dbContext . TryAddQueryType < T > ( ) ; var queryProvider = dbContext . GetDependencies ( ) . QueryProvider ; var querySource = new EntityQueryable < T > ( queryProvider ) ; var expression = Expression . Call ( null , FromSqlMethod . MakeGenericMethod ( typeof ( T ) ) , querySource . Expression , Expression . Constant ( sql ) , Expression . Constant ( parameters ) ) ; return queryProvider . CreateQuery < T > ( expression ) ; }
Executing a SQL statement and retrieve the result set directly frm the specified .
Executing a SQL statement and retrieve the result set directly frm the specified .
// Argument check // Add new query type if not exists // Get the query provider service instance // Build query source. Actually query source is just used to determine the final result item type. // Build LINQ expression for Entity Framework Core. // Return result
A  instance which can be used for retrieving the result or making a further query.
A instance which can be used for retrieving the result or making a further query .
DbContext
this
sql
RawSqlString
The SQL statement to be executing.
The SQL statement to be executing .
dbContext
None
parameters
Arguments provided along with the parameterized .
Arguments provided along with the parameterized .
typeparam
The type of the item in the result set.
The type of the item in the result set .