What The NuSoft Framework Gives You: Framework Components

posted on 12/19/07 at 02:00:34 am by Joel Ross

While I'm away on vacation, I figured I'd put up a series of posts on the NuSoft Framework. This is one of those posts.


I highlighted the EntityBase and plan to cover EntityList/EntityListReadOnly separately because there's so much in those ones. I'll cover the rest here. We have quite a few other components that you get in the Framework folder, and this is a quick view of what each is.

DatabaseColumnAttribute.cs: This is an attribute class that can be put on properties to signify to EntityBase's Initialize() method to expect that the property will be in the data row currently being loaded. By specifying an argument in the constructor, you can tell Initialize() to load this property with a field in the datarow by the name specified:

   1:  private int _numberOfOrders
   2:  [DatabaseColumn("NumOrders")]
   3:  public string NumberOfOrders
   4:  {
   5:      get { return _numberOfOrders; }
   6:      protected set { _numberOfOrders = value; }
   7:  }


This will look for a column with a name of NumOrders (reader["NumOrders"]) to load into the NumberOfOrders property.

EntityEventArgs.cs and EntityCancelEventArgs.cs: These are our custom event argument classes, and one or the other is used in all of the events in EntityBase. EntityEventArgs is used in the Init, PropertyChanged, Saved, Updated, Inserted and Deleted events. It inherits from EventArgs, and adds on an Entity property, which will be the entity that the event is happening on. For Saved, Updated, Inserted and Deleted, it will also have the SqlHelper set on it, so that you can do work with the database and have it partipate in the current transaction. EntityCancelEventArgs inherits from CancelEventArgs, but adds on an Entity property and the current SqlHelper so you can participate in the current transaction. It is used in the Saving, Updating, Inserting, and Deleting events. By setting the Cancel property to true, you can prevent the pending operation from occurring:

   1:  public void Customer_Saving(object sender EntityCancelEventArgs e)
   2:  {
   3:      e.Cancel = true;
   4:  }


This will prevent the pending save operation from happening, and will leave your entity in a dirty state.

SqlHelper.cs: This is your everyday typical SqlHelper helper class that's used on most projects that don't use Enterprise Library. We made one modification - it's not a static class, and it implements IDisposable, which means that you can use it in a using block, and have your connection cleaned up for you automatically:

   1:  using (SqlHelper helper = new SqlHelper())
   2:  {

3: helper.Execute(

"update Orders set ShippedDate = GetDate() where OrderId = 1", CommandType.Text, null);

   4:  }


This helps us ensure that our data connections are cleaned up for us, because in the Dispose method, we check for an open connection, and if it's open, the helper closes it.

ISearchable.cs and ISavable.cs: These are interfaces that define how you can use an entity. ISearchable is implemented by our EntityList, meaning you can search the list for a particular entity in the list. ISavable is implemented by the EntityBase and specifies that the entity can be saved.

MinToEmptyTypeConverter.cs: This is a type converter that specifies that if a property has a minimum value, it will be displayed as an empty string. For example, an int property will be defaulted to int.MinValue. This ensures that when you display this value in your UI, it will be displayed as String.Empty rather than -241213213 or whatever the minimum value for an int is.

Tags: | |

Categories: Development, Software, RCM Technologies