CommandType and CommandText configuration - lobodava/artisan-orm GitHub Wiki

  • Assign the stored procedure to the SqlCommand:

    cmd.UseProcedure("dbo.GetUserById");
    

    What it does inside:

    public static void UseProcedure(this SqlCommand cmd, string procedureName)
    {
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = procedureName;
    }
    
  • Assign the SQL text to the SqlCommand:

    cmd.UseSql("select * from vwUsers");
    
    -- or
    
    cmd.UseSql("select * from vwUsers where Id = @Id");
    

    What it does inside:

    public static void UseSql(this SqlCommand cmd, string sql)
    {
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = sql;
    }
    

See also: