PrepAway - Latest Free Exam Questions & Answers

What should you do?

You need to ensure that an exception is thrown when color names are set to less than two characters. What should you do?

PrepAway - Latest Free Exam Questions & Answers

A.
Add the following method to the Color partial class in Model\Color.cs:
protected overrride void OnPropertyChanged(string property)
{
if (property == “Name” && this.Name.Length < 2)
throw new ArgumentOutOfRangeException(“Name must be at least two characters”);
}

B.
Add the following code segment to the ContosoEntities partial class in Model\ContosoEntities.cs:
public override in SaveChanges(System.Data.Objects.SaveOptions options)
{
var changes = this.ObjectStateManager.GetObjectSateEntries(System.Data.EntityState.Added);
foreach (var change in changes)
{
if (change.Entity is Color)
if (((Color)change.Entity.Name.Length < 2) throw new ArgumentException(“Name too short”);
}
return base.SaveChanges(options);
}

C.
Add the following attribute to the Name property of the Color class in the entity designer file:
[StringLength(256, MinimumLength = 2)]

D.
Add the following method to the Color partial class in Model\Color.cs:
protected overrride void OnPropertyChanging(string property)
{
if (property == “Name” && this.Name.Length < 2)
throw new ArgumentOutOfRangeException(“Name must be at least two characters”);
}

5 Comments on “What should you do?


Leave a Reply