Calling a stored procedure from the Entity Framework, which returns a table with variable columns

I am using ASP.NET MVC 3 and EF 4.x

I have a procedure that returns a result set, but the columns are not fixed (it can return 25 columns or it can be 40 or 50).

How can I call this stored procedure from the Entity Framework?

When I use the import function, it queries Entity. But I can not select it, since none of the columns is fixed.

+3
source share
1 answer

Entity Framework is not suitable for this. This is good for statically defined data structures, not dynamic ones.

. Dapper, . , . NuGet -

using Dapper;

using (var cnn = new SqlConnection(myConnectionString))
{
    cnn.Open();
    var p = new DynamicParameters();
    p.Add("@params", "Id=21");
    var results = cnn.Query(sql:"GetMyData",
                            param: p, 
                            commandType: CommandType.StoredProcedure);
    foreach(IDictionary<string, object> result in results)
    {
        // Do something here.
    }
}

Query - Dapper, result - DapperRow, , IDictionary<string, object>, .

, .

+1

All Articles