The value of the OUTPUT variable cannot be obtained when the stored procedure is called by Linq to Entities.

Source: Internet
Author: User

Problem description:

Stored Procedure:

Alter procedure dbo. p_PurchaseSearch (@ fromdateDATETIME, @ todateDATETIME, @ notpayINT, @ idINT, @ custormerINT, @ istaxINT, @ specINT, @ companyINT, @ itemCountINT = 0 OUTPUT, @ pageIndexINT = 1 OUTPUT, @ pageSizeINT = 20 OUTPUT, @ runTimeINT = 0 OUTPUT)...

Import the stored procedure into the. edmx model. If a returned result set exists, a complex type is created.

When called in the. cs file:

ObjectParameter itemCount = new ObjectParameter ("itemCount", 10 );
ObjectParameter pageIndex = new ObjectParameter ("pageIndex", 1 );
ObjectParameter pageSize = new ObjectParameter ("pageSize", 20 );
ObjectParameter runTime = new ObjectParameter ("runTime", 10 );
Var _ result = dhhs. P_PurchaseSearch (fromdate, todate, notpay? 1: 0, id, customer, istax, spec, company, itemCount, pageIndex, pageSize, runTime). ToList ();

After the call, the OUTPUT value cannot be returned, that is, the input value does not change. After debugging, the stored procedure is found to be correct, and the background code is checked. It is found that the interface class controller is initialized previously:

DhhsdbEntities dhhs = newdhhsdbEntities ();

Fixed the problem:

ORZ can be instantiated before each action call. It is similar to the previous static method that makes different users talk about the same bug.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.