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

  • SEARCH
  • Home
  • 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 6809949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:08:49+00:00 2026-05-26T20:08:49+00:00

I am using Entity Framework 4.1 and do sometimes need to call stored procedures.

  • 0

I am using Entity Framework 4.1 and do sometimes need to call stored procedures. Some of these return ints as return values. For instance

CREATE PROCEDURE ...
...
INSERT INTO ...
SELECT @@Identity

(Update: removed return value, not relevant. We’re returning the identity)

I have the following code in my respository class:

var orderNo = context.Database.SqlQuery<int>("EXEC myProc").Single();

This fails with the error message The specified cast from a materialized 'System.Decimal' type to the 'System.Int32' type is not valid.

If I change the code above to

var orderNo = context.Database.SqlQuery<decimal>("EXEC myProc").Single();

everything works.

Now, I think that I should be able to return an int. What’s the proper way to do this?

  • 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-26T20:08:49+00:00Added an answer on May 26, 2026 at 8:08 pm

    I assume, based on the edit to your question – I clicked it shortly after your posting, then refreshed a bit later – that this is only an issue when you’re returning the identity?

    If so, it’s a decimal because @@IDENTITY (and SCOPE_IDENTITY) return numeric(38,0). See the answer to this question: Why does select SCOPE_IDENTITY() return a decimal instead of an integer?
    As noted there, casting to int should allow the EF to properly detect the type.

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

Sidebar

Related Questions

We are using Entity Framework 1.0. In some cases we need to explicitly open
Using Entity Framework 4 with stored procedures and SQL Server 2008 SP1... When running
I am using Entity Framework to populate a grid control. Sometimes when I make
I'm using entity framework 4. I have a stored procedure that just updates one
I'm using Entity Framework. In my database are stored persons and country of their
Using Entity Framework CodeFirst, how do I create a created datetime column that gets
Using Entity Framework 4 and code first how would I create a model that
Using Entity Framework 4 I want to create a base interface for my objects
I'm using entity framework to connect the database. I've a table(Let's call it File)
I'm using Entity Framework. I create a function in SQL Server where I'll import

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.