开发者

Return @@RowCount in LINQ to SQL INSERT

开发者 https://www.devze.com 2023-01-13 03:20 出处:网络
I am in the process of migrating some legacy code to LINQ to SQL and I am having some difficulty with the following Stored Procedure.

I am in the process of migrating some legacy code to LINQ to SQL and I am having some difficulty with the following Stored Procedure.

BEGIN
    INSERT INTO tblCMOEncounterHeader (
        submitter_organization_id, 
        submission_date, 
        begin_posting_date,
        end_posting_date, 
  开发者_JS百科      number_of_records_transmitted) 
    VALUES (
        @submitter_organization_id,
        @submission_date,
        @begin_posting_date,
        @end_posting_date,
        @number_of_records_transmitted)

    RETURN @@ROWCOUNT
END

Specifically, what does @@ROWCOUNT return when partnered with an INSERT? How would I accomplish the same thing in LINQ?


@@ROWCOUNT 

Returns the number of rows affected by the last statement

MSDN

In your case it will always return 1, I guess, or raise an error in case of constraint violation, etc.

Your LINQ to SQL code should definitely return (numsRowsAffected > 0);, i.e. a boolean value or something similar


Since you are only inserting one row, it should return 1. (Had you used INSERT INTO ... SELECT FROM... to insert multiple rows, it would be higher)

In LINQ, drag the stored proc from the Server Explorer, to the LINQ diagram (much as you did for the tables). It will create a method on the DataContext for the strored proc. (You may have to open the Method pane, from the context menu)

0

精彩评论

暂无评论...
验证码 换一张
取 消