Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 955347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:22:00+00:00 2026-05-16T00:22:00+00:00

I’m having a never-ending problem with trying to call a stored procedure from a

  • 0

I’m having a never-ending problem with trying to call a stored procedure from a controller – if I could I’d add a bounty to this as it’s taken way too much time already and I don’t know what else to do (but I don’t have the points). Based on my research it seems it’s a known bug, but not of the workarounds have worked for me so I’ll do my best to explain in hopes of a solution:

1- I create a stored procedure that looks something like this:

CREATE PROCEDURE [dbo].[db_name] 
    @start_dt datetime,
    @end_dt datetime

AS
BEGIN 

SET FMTONLY OFF;

SELECT [date],
    COUNT(visits) as Visits,
    SUM(CASE entrance WHEN '1' THEN 1 ELSE 0 END) AS ENT1,
    SUM(CASE entrance WHEN '2' THEN 1 ELSE 0 END) AS ENT2,
    SUM(CASE entrance WHEN '3' THEN 1 ELSE 0 END) AS ENT3,
    SUM(CASE entrance WHEN '4' THEN 1 ELSE 0 END) AS ENT4,
    SUM(CASE entrance WHEN '5' THEN 1 ELSE 0 END) AS ENT5
FROM some_view
WHERE [date] between @start_dt and @end_dt
group by [date]

END

2 – Then I created a LINQ to SQL entity object manually which has a property for each of the above returned columns (Date, Visits, ENT1, ENT2…ENT5).

3 – I tried dragging the stored proc as a function onto the said entity object in VS designer – but it would not allow me to as it says the “returned schema does not match the target class”. So I just dragged it elsewhere and a function is created (I even changed the return type to the object but didn’t work, see below).

**NOTE: I believe Visual Studio thinks the stored procedure returns an Int – not the table of values expected. ** The suggested fix for this type of problem was to make a dummy stored procedure that only has a simple select statement and replace it after dragging it to the object but that didn’t work either

4 – I tried everything I could think of in the controller, such as trying to return a IMultipleResults when calling the stored proc and converting it to the model object without any success.

The main issue seems to be that not rows are returned, just an int.

Thanks in advance for ANY help! I’m new to MVC so please feel free to tell me the whole way I’m going about it is off if you think it is.

UPDATE, here’s the generated XML of the model:

<?xml version="1.0" encoding="utf-8"?>
<Database Name="DB_Name" Class="nameDataContext" xmlns="http://schemas.microsoft.com/linqtosql/dbml/2007">
  <Connection Mode="WebSettings" ConnectionString="Data Source=some_data_source;Initial Catalog=some_db;Integrated Security=True" SettingsObjectName="System.Configuration.ConfigurationManager.ConnectionStrings" SettingsPropertyName="name_ConnectionString" Provider="System.Data.SqlClient" />
  <Table Name="" Member="Visits">
    <Type Name="Visit">
      <Column Name="Date" Type="System.DateTime" CanBeNull="false" />
      <Column Name="Visits" Type="System.Int32" CanBeNull="false" />
      <Column Name="ENT1" Type="System.Int32" CanBeNull="false" />
      <Column Name="ENT2" Type="System.Int32" CanBeNull="false" />
      <Column Name="ENT3" Type="System.Int32" CanBeNull="false" />
      <Column Name="ENT4" Type="System.Int32" CanBeNull="false" />
      <Column Name="ENT5" Type="System.Int32" CanBeNull="false" />
    </Type>
  </Table>
  <Function Name="dbo.sp_proc_name" Method="sp_proc_name">
    <Parameter Name="start_dt" Type="System.DateTime" DbType="DateTime" />
    <Parameter Name="end_dt" Type="System.DateTime" DbType="DateTime" />
    <ElementType Name="sp_proc_nameResult">
      <Column Name="date" Type="System.String" DbType="VarChar(30)" CanBeNull="true" />
      <Column Name="Visits" Type="System.Int32" DbType="Int" CanBeNull="true" />
      <Column Name="ENT1" Type="System.Int32" DbType="Int" CanBeNull="true" />
      <Column Name="ENT2" Type="System.Int32" DbType="Int" CanBeNull="true" />
      <Column Name="ENT3" Type="System.Int32" DbType="Int" CanBeNull="true" />
      <Column Name="ENT4" Type="System.Int32" DbType="Int" CanBeNull="true" />
      <Column Name="ENT5" Type="System.Int32" DbType="Int" CanBeNull="true" />
    </ElementType>
  </Function>
</Database>

UPDATE 2
When I run the stored procedure in Visual studio the output is a set of rows followed by:

No rows affected.
(129 row(s) returned)
@RETURN_VALUE = 0

I’m guessing it’s probably the last line that’s the culprit.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T00:22:01+00:00Added an answer on May 16, 2026 at 12:22 am

    No law states that one must use Linq2Sql or EF or nHibernate or SubSonic or whatever with MVC. So why not just write a little static function to call the proc and get the results back as a simple object graph rather than fussing with a whole ORM for a pretty direct RPC scenario.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.