我想弄清楚如何在使用MapToStoredProcedures时将参数注入实体框架6中。这甚至有可能吗?如何注入EF6/Code First?
我只是想将我当前登录的用户名从应用程序传递到存储过程,但我似乎无法弄清楚哪里的EF6做了实际的调用。
编辑:更多的信息
好,因此,没有MapToStoredProcedures(又名让EF6只是使用表直接),我可以做我的覆盖SaveChangesAsync方法如下:
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()
好吧,该工程伟大的代表EF的直接表操作。
我想要做的,而是在存储过程中处理所有这些 - 但我需要通过HttpContext.Current.User.Identity.Name.ToString()与我的删除存储过程来设置ArchiveBy参数。
希望这能更好地说明我正在尝试做什么。
我试图与EF的ChangeTracker工作......我的想法是,我会重写EF的Entity.Delete,因为这就是我想EF会调用存储过程,但我似乎无法弄清楚如何覆盖它... – John 2014-10-16 16:42:58