Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use an Update SPROC in Entity Framework 4.1
    primarykey
    data
    text
    <p>Background: I originally created an application on MVC3 and Entity Framework 4.1 (Database First &amp; Generated DBContext). I following a repository pattern. In order to meet Corp. DBA requirements, I need to convert all data access to using only SPROCS in order to promote the database. I'm getting stuck on a few things that I'm hoping to get answers on...</p> <ul> <li>Insert / Delete / Update Functions</li> </ul> <p>I've created my Insert, Delete, and Update Functions. I've added them to my EDM model and populated them in the 'Map Entity to Functions' tab on the Mapping details for the appropriate Entity. From what I've read, I shouldn't have the change the code in my repository class. Is this correct? (Code Below)</p> <pre><code> public void CreateReplacementReason (ReplacementReason replacementreason) { _db.ReplacementReasons.Add(replacementreason); } public void UpdateReplacementReason(ReplacementReason replacementreason) { var rr = FetchReplacementReason(replacementreason.PK_ReplacementReasonId); rr.DF_IsActive = replacementreason.DF_IsActive; rr.ReplacementReasonDesc = replacementreason.ReplacementReasonDesc; } </code></pre> <ul> <li>Returning Scope_Identity()</li> </ul> <p>How should a create method in my repository class look that calls a SPROC for which has a return value (Scope_Identity)? I thought I could put a return statement in my current method and change the return type. This, of course, did not work.</p> <pre><code>public int CreateReplacementReason (ReplacementReason replacementreason) { return _db.ReplacementReasons.Add(replacementreason); } </code></pre> <p>And this is the SPROC that is being called after being updated to return Scope_Identity()</p> <pre><code> INSERT INTO [dbo].[ReplacementReason] ([ReplacementReasonDesc], [DF_IsActive], [CreatedDateTime]) SELECT @ReplacementReasonDesc, @DF_IsActive, @CreatedDateTime SELECT SCOPE_IDENTITY() AS Id </code></pre> <p>Any any all help would be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload