Returning a DataTable using Entity Framework ExecuteStoreQuery

前端 未结 8 1418
清酒与你
清酒与你 2020-12-09 04:28

I am working with a system that has many stored procedures that need to be displayed. Creating entities for each of my objects is not practical.

Is it possible and

8条回答
  •  星月不相逢
    2020-12-09 05:25

    This method uses the connection string from the entity framework to establish an ADO.NET connection, to a MySQL database in this example.

    using MySql.Data.MySqlClient;
    
    public DataSet GetReportSummary( int RecordID )
    {
        var context = new catalogEntities();
    
        DataSet ds = new DataSet();
        using ( MySqlConnection connection = new MySqlConnection( context.Database.Connection.ConnectionString ) )
        {
            using ( MySqlCommand cmd = new MySqlCommand( "ReportSummary", connection ) )
            {
                MySqlDataAdapter adapter = new MySqlDataAdapter( cmd );
                adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                adapter.SelectCommand.Parameters.Add( new MySqlParameter( "@ID", RecordID ) );
                adapter.Fill( ds );
            }
        }
        return ds;
    }
    

提交回复
热议问题