Database Reference
In-Depth Information
if (!u.ValidateAddress())
throw new ArgumentException("The value has incorrect format. Attributes are
empty or State is incorrect");
return u;
}
// Example of the class method
[SqlMethod(
OnNullCall = false,
IsDeterministic = true,
DataAccess=DataAccessKind.None
)]
public double CalculateShippingCost(USPostalAddress destination)
{
// Calculating shipping cost between two addresses
if (destination.State == this.State)
return 15.0;
else
return 25.0;
}
// IBinarySerializer.Read
public void Read(System.IO.BinaryReader r)
{
_address = r.ReadString();
_city = r.ReadString();
_state = r.ReadString();
_zipCode = r.ReadString();
}
// IBinarySerializer.Write
public void Write(System.IO.BinaryWriter w)
{
w.Write(_address);
w.Write(_city);
w.Write(_state);
w.Write(_zipCode);
}
}
As you see, the type includes four different public attributes/properties ( Street , City , State , and ZIPCode ) and
several methods. Some of the methods ( ToString , Parse , Read , and Write ) are required to support type creation
and serialization. Another ( CalculateShippingCost ) is an example of a type functionality enhancement.
In the database, you can use that type when defining table columns, variables, and parameters. Listing 14-3 and
Figure 14-1 show an example of this.
 
Search WWH ::




Custom Search