locked
How to send fewer parameters when using MapToStoredProcedures in Entity Framework RRS feed

  • Question

  • Hi,

    We are using “MapToStoredProcedures” to setup store procedure in EntityFramework. How can we send fewer parameters than the number of properties defined in Entity while updating the record? 

    Thanks

    Friday, March 24, 2017 11:09 AM

All replies

  • Hi Yug Narula,

    >>We are using “MapToStoredProcedures” to setup store procedure in EntityFramework. How can we send fewer parameters than the number of properties defined in Entity while updating the record? 

    Based on your description, you want to send fewer parameters than the number of properties defined in Entity while updating the record when using “MapToStoredProcedures”. As far as I know, if you use MapToStoredProcedures, you just modify the entity object, then call SaveChanges to update the records, it seems that you don't consider to send parameters to stored procedure.

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, March 27, 2017 6:51 AM
  • Hi,

    I found that I can mention “[DatabaseGenerated(DatabaseGeneratedOption.Computed)]” on properties which we don’t want to send to procedure. But there are few properties which are required in case of insert but not for update. Is this possible to do while using EntityFramework?

    Thanks.


    Monday, March 27, 2017 12:13 PM
  • Hi Yug Narula,

    You could not change input parameters in your Store Procedure without  “[DatabaseGenerated(DatabaseGeneratedOption.Computed)]”, which will throw exception.

    You could change your update sql statement without related parameters. like below, I remove the parameter named @URL on SQL statement.

    USE [Blogging]
    GO
    
    /****** Object: SqlProcedure [dbo].[Blog_Update] Script Date: 3/31/2017 1:41:08 PM ******/
    SET ANSI_NULLS ON
    GO
    
    SET QUOTED_IDENTIFIER ON
    GO
    
    ALTER PROCEDURE [dbo].[Blog_Update]
        @BlogId [int],
        @Name [nvarchar](max),
        @Url [nvarchar](max)
    AS
    BEGIN
        UPDATE [dbo].[Blog]
        SET [Name] = @Name
        WHERE ([BlogId] = @BlogId)
        
        SELECT t0.[CreatedDate]
        FROM [dbo].[Blog] AS t0
        WHERE @@ROWCOUNT > 0 AND t0.[BlogId] = @BlogId
    END
    

    Best regards,

    Cole Wu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, March 31, 2017 5:55 AM