2

I am using Entity Framework 6.0.

I am having scalar valued function in SQL Server signatured as

fn_CartAmount(@CartId bigint) RETURNS decimal(18,2)


I want to call this function from Entity Framework and get its result.

1 Answer 1

3

You could try something like :

    public decimal GetCartAmount(int cartId)
    {

        var returnCode = new SqlParameter("@ReturnCode", SqlDbType.Bit) { Direction = ParameterDirection.Output };

        object[] parameters =
        {
            new SqlParameter(@"CartId", SqlDbType.BigInt) {Value = cartId}
            , returnCode
        };

        string command = string.Format("exec @ReturnCode = dbo.fn_CartAmount @CartId");
        Database.ExecuteSqlCommand(command, parameters);


        return (decimal)returnCode.Value;
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.