ice.NET Key Concepts: Attributes

Objects as well as relationships can have attributes.

Attributes are of one of the following value type:

  • String
  • Enumeration
  • Bool
  • Integer
  • Real
  • DateTime

Example

This example shows how to set and retrieve attribute values. Notice that the declaring type name is part of the attribute definition identity.

IObjType pObjType = Repository.GetObjTypeByName("PDTec.ICR.Booking");
IObject pBooking  = null;

//
// Create a booking and set attribute values...
//

Repository.ExecuteTransaction(delegate()
{
    pBooking = pObjType.CreateObject(Repository.GetFolderByKey("ICR.Data.Bookings"), "New Booking", "");

    pBooking.SetAttrValue("PDTec.ICR.Booking", "FromDate",        DateTime.UtcNow);
    pBooking.SetAttrValue("PDTec.ICR.Booking", "ToDate",          DateTime.UtcNow.AddDays(2.0));
    pBooking.SetAttrValue("PDTec.ICR.Booking", "PaymentReceived", false);
    pBooking.SetAttrValue("PDTec.ICR.Booking", "BookingStatus",   Repository.GetAttrTypeByName("PDTec.ICR.BookingStatus").GetEnumValues()[0]);
    pBooking.SetAttrValue("PDTec.ICR.Booking", "Price",           200.0);
});

//
// Retrieve and print attribute values...
//

Console.WriteLine("FromDate: "         + pBooking.GetAttrValue("PDTec.ICR.Booking", "FromDate"));
Console.WriteLine("ToDate: "           + pBooking.SetAttrValue("PDTec.ICR.Booking", "ToDate"));               
Console.WriteLine("PaymentReceived: "  + pBooking.SetAttrValue("PDTec.ICR.Booking", "PaymentReceived"));
Console.WriteLine("BookingStatus: "    + pBooking.SetAttrValue("PDTec.ICR.Booking", "BookingStatus"));
Console.WriteLine("Price: "            + pBooking.SetAttrValue("PDTec.ICR.Booking", "Price"));         

Important notice: These examples use the low-level ice.NET API. Implementing Business Objects and using the Business Objects Builder (icebob.exe) enables more type-safe access to attributes, relationships and domain-specific functionality.