RelationalQueryableExtensions RelationalQueryableExtensions Class


Relational database specific extension methods for LINQ queries.

public static class RelationalQueryableExtensions
Public Module RelationalQueryableExtensions


System.Object.Equals(System.Object) System.Object.Equals(System.Object) Inherited from System.Object
System.Object.Equals(System.Object, System.Object) System.Object.Equals(System.Object, System.Object) Inherited from System.Object
FromSql<TEntity>(IQueryable<TEntity>, String, Object[]) FromSql(Of TEntity)(IQueryable(Of TEntity), String, Object())

Creates a LINQ query based on a raw SQL query.

If the database provider supports composing on the supplied SQL, you can compose on top of the raw SQL query using LINQ operators -

context.Blogs.FromSql("SELECT * FROM dbo.Blogs").OrderBy(b => b.Name)

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 -

context.Blogs.FromSql("SELECT * FROM [dbo].[SearchBlogs]({0})", userSuppliedSearchTerm)

You can also construct a DbParameter and supply it to as a parameter value. This allows you to use named parameters in the SQL query string -

context.Blogs.FromSql("SELECT * FROM [dbo].[SearchBlogs]({@searchTerm})", new SqlParameter("@searchTerm", userSuppliedSearchTerm))

System.Object.GetHashCode() System.Object.GetHashCode() Inherited from System.Object
System.Object.GetType() System.Object.GetType() Inherited from System.Object
System.Object.MemberwiseClone() System.Object.MemberwiseClone() Inherited from System.Object
System.Object.ReferenceEquals(System.Object, System.Object) System.Object.ReferenceEquals(System.Object, System.Object) Inherited from System.Object
System.Object.ToString() System.Object.ToString() Inherited from System.Object