I'm trying to figure out how to inject a parameter into Entity Framework 6 when using MapToStoredProcedures. Is this even possible?
I just want to pass my currently logged in username from the application to the stored procedure, but I can't seem to figure out WHERE EF6 does the actual call.
EDIT : A bit more information
Ok, so WITHOUT MapToStoredProcedures (aka letting EF6 just use tables directly) I can do the following in my overridden SaveChangesAsync method:
For Each Entry As DbEntityEntry In Me.ChangeTracker.Entries().Where(Function(o) o.State = EntityState.Deleted)
If TypeOf Entry.Entity Is ISoftDelete Then
'Implements Soft Delete interface, so let's do what needs doing.
Select Case Entry.Entity.GetType()
Case GetType(OS)
Dim _thisOS As OS = TryCast(Entry.Entity, OS)
Using db As New AppRegistrationContext
_thisOS = Await db.OSSet.Include("OSType").FirstOrDefaultAsync(Function(o) o.ID = _thisOS.ID)
End Using
If Not _thisOS Is Nothing Then
Try
Entry.Reference("OSType").CurrentValue = _thisOS.OSType
Catch ex As Exception
Debug.Print(ex.ToString)
End Try
End If
Case GetType(Server)
Case Else
'Do nothing - only filling in extra information for those that we need to
End Select
'Set the archival bits
Entry.Property("Archive").CurrentValue = True
Entry.Property("ArchiveDate").CurrentValue = Date.Now
Entry.Property("ArchiveBy").CurrentValue = HttpContext.Current.User.Identity.Name.ToString()
'Mark it modified
Entry.State = EntityState.Modified
End If
Next
Return Await MyBase.SaveChangesAsync()
Alright, that works great with direct-table manipulation on EF's behalf.
What I want to do instead, is handle all of this in stored procedures - but I need to pass HttpContext.Current.User.Identity.Name.ToString() WITH my delete stored procedure to set the ArchiveBy parameter.
Hopefully this better illustrates what I am attempting to do.