Databases Reference
In-Depth Information
OnUnitsInStockChanging(value);
ReportPropertyChanging(“UnitsInStock”);
_UnitsInStock = StructuralObject.SetValidValue(value);
ReportPropertyChanged(“UnitsInStock”);
OnUnitsInStockChanged();
}
}
private Nullable<global::System.Int16> _UnitsInStock = 0;
NOTE
When writing code by hand, you would typically and rely on the compiler to choose a
DefaultValueAttribute constructor that matches the type of default value directly,
such as the DefaultValueAttribute(Int16) for the UnitsInStock property.
However, generating this code programmatically is challenging. To keep implementation
simple, the text template in this sample always generates the
DefaultValueAttribute(Type, String) overload .
Property Interaction Rules
Information systems commonly have a requirement to track information regarding impor-
tant changes in the state of an entity. In the case of the Northwind Traders web applica-
tion, you might need to keep track of when each particular order was submitted in the
SubmittedDate property of the Order entity. Here is a test that illustrates the expected
behavior:
[TestMethod]
public void OrderStatus_SetsSubmittedDate()
{
using (new TransactionScope())
using (var context = new NorthwindEntities())
{
var order = new Order();
order.OrderDate = DateTime.Today;
order.OrderStatus = (int)OrderStatus.Submitted;
context.Orders.AddObject(order);
context.SaveChanges();
Assert.IsNotNull(order.SubmittedDate);
Assert.AreEqual(DateTime.Today, order.SubmittedDate.Value.Date);
}
}
 
 
Search WWH ::




Custom Search