1

このストアド プロシージャを呼び出す必要がありますが、それを .dbml に取り込むと、結果が ISingleResult に変換されます。すべてのパラメーターでこれを適切に呼び出す方法がわかりません。これは私の現在のコードですが、「結果を返す」と「無効な表現用語「戻り」」というエラーが表示されます。ありがとうございました。

public static int CreateNewTransferee(CreateTransferee model)
    {
        using (var db = new NJB.NJBDataContext())
        {
                var result = db.SP_AddTransferee(
                model.TransferEffectiveDate,
                model.TransfereeName,
                model.TransfereeNoticeAddressLine1,
                model.TransfereeNoticeAddressLine2,
                model.TransfereeNoticeCity,
                model.TransfereeNoticeState,
                model.TransfereeNoticeZip,
                model.TransfereeNoticePhone,
                model.TransfereePaymentAddressLine1,
                model.TransfereePaymentAddressLine2,
                model.TransfereePaymentCity,
                model.TransfereePaymentState,
                model.TransfereePaymentZip,
                model.TransfereePaymentPhone,

            return (int) result.ReturnValue;
        }
    }

更新: SP は次のとおりです。

 ALTER PROCEDURE [dbo].[SP_AddTransferee] 
-- Add the parameters for the stored procedure here
@TransferEffectiveDate datetime,
@TransfereeName varchar(50),
@TransfereeNoticeAddressLine1 varchar(50),
@TransfereeNoticeAddressLine2 varchar(50),
@TransfereeNoticeCity varchar(50),
@TransfereeNoticeState varchar(2),
@TransfereeNoticeZip varchar(12),
@TransfereeNoticePhone varchar(50),
@TransfereePaymentAddressLine1 varchar(50),
@TransfereePaymentAddressLine2 varchar(50),
@TransfereePaymentCity varchar(50),
@TransfereePaymentState varchar(50),
@TransfereePaymentZip varchar(50),
@TransfereePaymentPhone varchar(50)

AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
INSERT INTO TransfereeList
VALUES (@TransferEffectiveDate, @TransfereeName, @TransfereeNoticeAddressLine1, @TransfereeNoticeAddressLine2,
    @TransfereeNoticeCity, @TransfereeNoticeState, @TransfereeNoticeZip, @TransfereeNoticePhone, 
    @TransfereePaymentAddressLine1, @TransfereePaymentAddressLine2, 
    @TransfereePaymentCity, @TransfereePaymentState, @TransfereePaymentZip, @TransfereePaymentPhone);

SELECT SCOPE_IDENTITY();

終わり

4

3 に答える 3

4

閉じ括弧とセミコロンがありません。

public static int CreateNewTransferee(CreateTransferee model)
{
    using (var db = new NJB.NJBDataContext())
    {
        var result = db.SP_AddTransferee(
            model.TransferEffectiveDate,
            model.TransfereeName,
            model.TransfereeNoticeAddressLine1,
            model.TransfereeNoticeAddressLine2,
            model.TransfereeNoticeCity,
            model.TransfereeNoticeState,
            model.TransfereeNoticeZip,
            model.TransfereeNoticePhone,
            model.TransfereePaymentAddressLine1,
            model.TransfereePaymentAddressLine2,
            model.TransfereePaymentCity,
            model.TransfereePaymentState,
            model.TransfereePaymentZip,
            model.TransfereePaymentPhone);
        //                              ^^ right here

        return (int) result.ReturnValue;
    }
}
于 2013-09-20T16:10:58.737 に答える
0

あなたのコードは不完全なようです...??? 正しければ、このようにします..

public static int CreateNewTransferee(CreateTransferee model)
    {
        var result;
        using (var db = new NJB.NJBDataContext())
        {
                result = db.SP_AddTransferee(
                model.TransferEffectiveDate,
                model.TransfereeName,
                model.TransfereeNoticeAddressLine1,
                model.TransfereeNoticeAddressLine2,
                model.TransfereeNoticeCity,
                model.TransfereeNoticeState,
                model.TransfereeNoticeZip,
                model.TransfereeNoticePhone,
                model.TransfereePaymentAddressLine1,
                model.TransfereePaymentAddressLine2,
                model.TransfereePaymentCity,
                model.TransfereePaymentState,
                model.TransfereePaymentZip,
                model.TransfereePaymentPhone,    

        }
         return result;
    }
于 2013-09-20T15:33:40.137 に答える
0

result.First()を試し て整数を取得できます。

于 2013-09-20T15:00:37.570 に答える