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 8151325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:20:53+00:00 2026-06-06T15:20:53+00:00

I have this stored procedure, which is mapped in an Entity Framework 4.1 object.

  • 0

I have this stored procedure, which is mapped in an Entity Framework 4.1 object. The call is made within the

using (TransactionScope transaction = new TransactionScope())
{
            try
            {
                DbEntity.Car.AddObject(CarInfo);
                DbEntity.SaveChanges();

/* Other object savings */

                transaction.Complete();

                DbEntity.AcceptAllChanges();
            }
            catch (Exception exp)
            {
                throw exp;
            }
            finally
            {
                DbEntity.Dispose();
            }
}

I see the stored procedure mapping done currently. If I execute the stored procedure alone on MS SQL server, it executes it correctly.

Here is the stored procedure

ALTER PROCEDURE [dbo].[Carinsert] @Qty               INT
                              ,@StyleID          INT
                              ,@TFee             MONEY
                              ,@HWayTax          MONEY
                              ,@OFees            MONEY
                              ,@OFeesDescription NTEXT
                              ,@MUp              DECIMAL(18, 4)
                              ,@BAss             MONEY
                              ,@PriceMSRP        MONEY
                              ,@PriceSpecial     MONEY
AS
BEGIN
  SET nocount ON

  DECLARE @PTotal MONEY
  DECLARE @TaxFeesNet MONEY
  DECLARE @CarID INT

  SET @TaxFeesNet = Isnull(@TFee, 0) + Isnull(@HWayTax, 0)
                    + Isnull(@OFees, 0)

  IF( @PriceSpecial IS NULL )
    BEGIN
        SET @PTotal = @PriceMSRP + @TaxFeesNet
    END
  ELSE
    BEGIN
        SET @PTotal = @PriceSpecial + @TaxFeesNet
    END

  INSERT INTO Car
              (Qty
               ,StyleID
               ,MUp
               ,BAss
               ,PriceMSRP
               ,PriceSpecial
               ,TFee
               ,HWayTax
               ,OFees
               ,OFeesDescription
               ,PriceTotal)
  VALUES      (@Qty
               ,@StyleID
               ,@MUp
               ,@BAss
               ,@PriceMSRP
               ,@PriceSpecial
               ,@TFee
               ,@HWayTax
               ,@OFees
               ,@OFeesDescription
               ,@PTotal)

    SELECT Scope_identity() AS CarID
END 

If I execute this like on MS SQL it calculates the PriceTotal column in the table as 3444.00, which is correct.

    @Qty= 5,
    @StyleID = 331410,
    @TFee = NULL,
    @HWayTax = NULL,
    @OFees = NULL,
    @OFeesDescription = NULL,
    @MUp = 4,
    @BAss = 10000,
    @PriceMSRP = 20120,
    @PriceSpecial = 3444

When I run the MVC web application, and I debug & see these are the values passed and the PriceTotal comes to 20120.00

I couldn’t figure out why it does not do the IF ELSE calculation & use the price.

Does anybody else see something weird? This has been daunting for few days now. Any help appreciated. Thanks

Update
I updated the title to better guide others

  • 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-06-06T15:20:55+00:00Added an answer on June 6, 2026 at 3:20 pm

    After few minutes of posting the question, I figured it all out.

    There was actually 2 bug.

    1. Entity framework used the UPDATE stored procedure even when I try to INSERT new records. Just for records, the UPDATE stored procedure required the CarID [primary key]. May be EF first does the INSERT and then does the UPDATE right away, even for creating new records?

    2. The UPDATE sproc had a bug checking for NULL using <>. It should have been IS NOT NULL

    In anycase, now This is a bigger issue. How to force EF to use INSERT sproc and not the UPDATE when I only want to do is create a new record?

    I tried
    DbEntityContext.ObjectStateManager.ChangeObjectState(carInfo, EntityState.Added);
    and still EF kept on calling the UPDATE sproc.

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

Sidebar

Related Questions

I have this code which calls a stored procedure within ZEND. Is there a
I have this stored procedure which I am using to populate a user table.
I'm using this guide to call stored procedure in my projet which using EF4
I have a stored procedure that logs some data, how can I call this
I have a stored procedure that updates a table using linq, eg: (this is
I have this stored procedure which get data from excell and then update status:
Hi i have a stored procedure which will have a dynamic clause, this is
I have a stored procedure which updates a database using the parameters I supply
I have a Stored procedure which schedules a job. This Job takes a lot
Have you encountered this exception for a stored procedure which does indeed have a

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.