本文整理汇总了VB.NET中System.Data.Objects.ObjectContext.SavingChanges事件的典型用法代码示例。如果您正苦于以下问题:VB.NET ObjectContext.SavingChanges事件的具体用法?VB.NET ObjectContext.SavingChanges怎么用?VB.NET ObjectContext.SavingChanges使用的例子?那么, 这里精选的事件代码示例或许可以为您提供帮助。您也可以进一步了解该事件所在类System.Data.Objects.ObjectContext
的用法示例。
在下文中一共展示了ObjectContext.SavingChanges事件的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: AdventureWorksProxy
Public Class AdventureWorksProxy
' Define the object context to be provided.
Private contextProxy As New AdventureWorksEntities()
Public Sub New()
' When the object is initialized, register the
' handler for the SavingChanges event.
AddHandler contextProxy.SavingChanges, AddressOf context_SavingChanges
End Sub
' Method that provides an object context.
Public ReadOnly Property Context() As AdventureWorksEntities
Get
Return contextProxy
End Get
End Property
' SavingChanges event handler.
Private Sub context_SavingChanges(ByVal sender As Object, ByVal e As EventArgs)
' Ensure that we are passed an ObjectContext
Dim context As ObjectContext = TryCast(sender, ObjectContext)
If context IsNot Nothing Then
' Validate the state of each entity in the context
' before SaveChanges can succeed.
For Each entry As ObjectStateEntry In context.ObjectStateManager.GetObjectStateEntries(EntityState.Added Or EntityState.Modified)
' Find an object state entry for a SalesOrderHeader object.
If Not entry.IsRelationship AndAlso (entry.Entity.GetType() Is GetType(SalesOrderHeader)) Then
Dim orderToCheck As SalesOrderHeader = TryCast(entry.Entity, SalesOrderHeader)
' Call a helper method that performs string checking
' on the Comment property.
Dim textNotAllowed As String = Validator.CheckStringForLanguage(orderToCheck.Comment)
' If the validation method returns a problem string, raise an error.
If textNotAllowed <> String.Empty Then
Throw New ArgumentException(String.Format("Changes cannot be " & _
"saved because the {0} '{1}' object contains a " & _
"string that is not allowed in the property '{2}'.", _
entry.State, "SalesOrderHeader", "Comment"))
End If
End If
Next
End If
End Sub
End Class