Which code segment should you place in the entity’s partial class?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to develop an application.
You use the Entity Framework Designer to create the following Entity Data Model.

You write a method named ValidatePostalCode to validate the postal code for the application. You
need to ensure that the ValidatePostalCode method is called before the PostalCode property set
method is completed and before the underlying value has changed. Which code segment should you
place in the entity’s partial class?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4 to develop an application.
You use the Entity Framework Designer to create the following Entity Data Model.

You write a method named ValidatePostalCode to validate the postal code for the application. You
need to ensure that the ValidatePostalCode method is called before the PostalCode property set
method is completed and before the underlying value has changed. Which code segment should you
place in the entity’s partial class?

A.
Public Property ValidatedPostalCode As String
Get
Return _PostalCode
End Get
Set(ByVal value As String)
PostalCode – StructuralObject.SetValidValue( _
“ValidatePostalCode”, False)
End Set
End Property

B.
Private Sub OnPostalCodeChanging(ByVal value As String)
ValidatePostalCode(value)
End Sub

C.
Public Property ValidatedPostalCode As String
Get
Return _PostalCode
End Get
Set(ByVal value As String)
ValidatePostalCode(value) _
PostalCode = value
End Set
End Property

D.
Private Sub OnPostalCodeChanged(ByVal value As String)
PostalCode = GetValidValue(Of String)
(value, “ValidatePostalCode”, False, True)
End Sub

Explanation:

Another area of extensibility is with the partial methods created on each entity type. There is a pair
of partial methods called OnXxxChanging and OnXxxChanged for each property, in which Xxx is the
name of the property. The OnXxxChanging method executes before the property has changed, and
the OnXxxChanged method executes after the property has changed. To implement any of the
partial methods, create a partial class and add the appropriate partial method with implementation
code.
CHAPTER 6 ADO.NET Entity Framework
Lesson 1: What Is the ADO.NET Entity Framework?
Partial Classes and Methods(page 390)
How to: Execute Business Logic During Scalar Property Changes
(http://msdn.microsoft.com/en-us/library/cc716747.aspx)



Leave a Reply 0

Your email address will not be published. Required fields are marked *