Stored procedure returning dynamic columns in Entity Framework

1.7k Views Asked by At

I have a function calling a SQL Server stored procedure using Entity Framework 6.2.

The stored procedure returns a result set which has different number of columns on each call, and column names may vary on each call.

Function getListOfDocs() As JsonResult
            Try
                Using entities As PromatEntities = New PromatEntities()

                    Dim param(1) As SqlParameter

                    param(0) = New SqlParameter("@ProjID", SqlDbType.Int)
                    param(0).Value = vProjectId

                    Dim query = entities.Database.SqlQuery(Of "help required here")("sp_EIP_IPSSDocMaster_Get", param) // cannot handle this case as entity framework needs type
                    Dim lstDocs = query.ToList
                End Using
                Return Json(New With {lstDocs}, JsonRequestBehavior.AllowGet)
            Catch ex As Exception
                ClsCommon.ExceptionManager(ex)
                Return Nothing
            End Try
        End Function

But Entity Framework doesn't allow anonymous types in database.SqlQuery. Can anyone suggest a way to solve the issue and get the anonymous type data to view?

0

There are 0 best solutions below