Returning a DataTable using Entity Framework ExecuteStoreQuery

前端 未结 8 1377
清酒与你
清酒与你 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:22

    Maybe your stored procedure could return a complex type? http://blogs.msdn.com/b/somasegar/archive/2010/01/11/entity-framework-in-net-4.aspx

    0 讨论(0)
  • 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;
    }
    
    0 讨论(0)
提交回复
热议问题