Which code segment should you place in the entitys partial class?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 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 entitys partial class?

You use Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.0 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 entitys partial class?

A.
partial void OnPostalCodeChanged(string value)
{
PostalCode = GetValidValue<string>(value, “ValidatePostalCode”, false, true) ;
}

B.
public string ValidatedPostalCode
{
set
{
ValidatePostalCode(value);
_PostalCode = value;
}
get
{
return _PostalCode;
}
}

C.
partial void OnPostalCodeChanging(string value)
{
ValidatePostalCode(value);
}

D.
public string ValidatedPostalCode
{
set
{
_PostalCode = StructuralObject.SetValidValue(“ValidatePostalCode”, false);
}
get
{
return _PostalCode;
}
}

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 *