Returning a DataTable using Entity Framework ExecuteStoreQuery

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

    Yes it can easily be done like this:

    var table = new DataTable();
    using (var ctx = new SomeContext())
    {
        var cmd = ctx.Database.Connection.CreateCommand();
        cmd.CommandText = "Select Col1, Col2 from SomeTable"; 
    
        cmd.Connection.Open();
        table.Load(cmd.ExecuteReader());
    }
    

提交回复
热议问题