Note that there are some explanatory texts on larger screens.

plurals
  1. POSaving the results of a SELECT Stored procedure ASP.NET Entity Framework
    text
    copied!<p>I am searching all over the web for an answer to this question and I have come up short. I have a simple stored procedure that selects columns from a view, I would like to save this data in a Model in my program. However, when I call the stored procedure it has a return type of ObjectResult, so I have been trying to implement this but I am at a loss for what datatype to use in my model.</p> <pre><code>CREATE PROCEDURE [dbo].[GetPartnerCompanyRelationships] @inputCoid INT AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here SELECT [CoId] ,[CompanyName] ,[CompanyId] ,[PartnerCoId] ,[PartnerCompanyName] ,Count(*) as DocumentTotal FROM vwDocuments where coid = @inputCoid and DocumentType = 'order' and PartnerCoId &lt;&gt; @inputCoid group by [CoId] ,[CompanyName] ,[CompanyId] ,[PartnerCoId] ,[PartnerCompanyName] union all SELECT [CoId] ,[CompanyName] ,[CompanyId] ,[PartnerCoId] ,[PartnerCompanyName] ,Count(*) as DocumentTotal FROM vwDocuments where PartnerCoId = @inputCoid and DocumentType = 'order' and CoId &lt;&gt; @inputCoid group by [CoId] ,[CompanyName] ,[CompanyId] ,[PartnerCoId] ,[PartnerCompanyName] END </code></pre> <p>The procedure just selects these columns.</p> <p>I want my model to hold this data so I can reference it in a View and build a table from it but the issue is saving this data.</p> <pre><code>public ObjectResult GetPartnerCompanyRelationships(int coid) { using (var context = LTPortalEntities.getEntities()) { ObjectResult x = context.GetPartnerCompanyRelationships(coid); return x; } } </code></pre> <p>This is what I have tried in my datahelper class, and in my Controller:</p> <pre><code>var companyList = _da.GetPartnerCompanyRelationships(coid); foreach (vwDocument item in companyList) { MyDashBoard.CompanyList.Add(item); } </code></pre> <p>If this is vague please let me know what to include, this is my first shot at getting information with a stored procedure.</p> <p>One of the other issues I have encountered is trying to ORDER BY with a select from a view, my procedure didn't like that very much. So I am wondering if creating a function would be easier? If so, how to get that into the edmx.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload