DatabaseExtensionsGetCommand Method
This extension method is used to get a command object in a state ready to execute the specified
command text on the given data context.
Namespace: EWSoftware.EntityFrameworkAssembly: EWSoftware.EntityFramework (in EWSoftware.EntityFramework.dll) Version: 2025.11.12.0
public static SqlCommand GetCommand(
this DbContext dataContext,
string commandText,
params SqlParameter[] parameters
)
<ExtensionAttribute>
Public Shared Function GetCommand (
dataContext As DbContext,
commandText As String,
ParamArray parameters As SqlParameter()
) As SqlCommand
public:
[ExtensionAttribute]
static SqlCommand^ GetCommand(
DbContext^ dataContext,
String^ commandText,
... array<SqlParameter^>^ parameters
)
[<ExtensionAttribute>]
static member GetCommand :
dataContext : DbContext *
commandText : string *
parameters : SqlParameter[] -> SqlCommand
- dataContext DbContext
- The data context to use
- commandText String
- The command text can be a stored procedure with or without parameters or a
literal SQL statement. It will be used when creating the command object.
- parameters SqlParameter
- Zero or more parameters for the command.
SqlCommandReturns a
SqlCommand object.In Visual Basic and C#, you can call this method as an instance method on any object of type
DbContext. When you use instance method syntax to call this method, omit the first parameter. For more information, see
Extension Methods (Visual Basic) or
Extension Methods (C# Programming Guide).
The command will be associated with the connection from the data context instance on which
this method is called with the command timeout set to the value from the data context if one has been
set. The command text can be a stored procedure with or without parameters or a literal SQL statement.
The returned command is ready to execute or modify further with parameters. This is useful for
situations in which a
SqlDataReader is needed, you need more control when executing a
stored procedure, or the stored procedure returns multiple result sets.
using var dataContext = new MyDbContext().NoTracking();
// Set up the daily schedule command and data adapter
var cmdDailySchedule = dc.GetCommand("spDailyScheduleInfo",
new SqlParameter("@paramBidGroup", SqlDbType.Char, 4),
new SqlParameter("@paramDate", SqlDbType.DateTime));
var daDailySchedule = new SqlDataAdapter(cmdDailySchedule);