What The NuSoft Framework Gives You

posted on 12/16/07 at 09:00:11 pm 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.

Ok. You just got done sitting back and relaxing, and now you've got your generated framework. Great. Now you're ready to go!

But what exactly did you get?

In your root folder, you should have a solution file, named after your Namespace you used while generating. You'll also have another folder named after your DomainNamespace you used when generating. If you selected StoredProcedures for your SQLType, then you'll also have a Database folder.

In that Database folder, you'll find a database project, with the standard folders it starts with, but under the Create Scripts folder, you have a Stored Procedures folder, which has all of your scripts in it. They are all in separate files, and you'll need to run these against the database before you get too far.

In the other folder (Domain, Business, Core, or whatever you called it) is the core of the framework. The files in here are your business entities. Each one has a <entity>.cs file and a Generated.<entity>.cs file. When you open the project, the Generated.<entity>.cs file will be a sub-item of the <entity>.cs file, so it's there, but hidden.

In the Framework folder, you'll find the standard files for the NuSoft Framework:

  1. EntityBase - every entity inherits from EntityBase. This provides a default set of methods and properties, default implementations for some methods, and a definition of a standard interface our entities will have. This is also responsible for loading and initializing entities from database readers.
  2. EntityBaseReadOnly - This is used for any classes that have no primary key. You can get a list of all of them and you can get them by primary key. You can't modify it, and you can't create new ones.
  3. EntityList - this provides us with a custom generic collection we can use for lists of our entities. It handles loading and saving of child collections for an entity.
  4. EntityListReadOnly - this gives us a way to have a read-only collection that will not get saved when we update our entities.
  5. DatabaseColumnAttribute - we use this attribute in our entities to flag a column as coming from the database. You can use this in your own custom objects to have them loaded automatically by the framework.
  6. EntityEventArgs and EntityCancelEventArgs - our entities have a few events that you can handle, and we pass along custom event arguments. We typically have an "ing" and a "ed" event - Saving and Saved, Inserting and Inserted, etc. The "ing" event will use the EntityCancelEventArgs, which allows the handler to cancel the pending event. So by saying e.Cancel = true; in the Saving event, we can prevent a Save from happening.
  7. SqlHelper - this is a fairly standard SQL Helper class that allows us to access SQL Server. It relies on a ConnectionString being in the ConnectionStrings section of your config file, based on the property you set for the connection string key.
  8. ISearchable and ISavable: Two interfaces that are used to specifiy that our list is searchable and that our entities are savable.

I'll go into more details on the framework files at another time. For now, that's good enough to get you going.

Back to the domain folder. The <entity>.cs file will be where you'll add your custom code. The Generated.<entity>.cs file is designed to be left alone, so it can be regenerated if you need to. This isn't a hard and fast rule, but be aware that the file will get overwritten if you regenerate.

The Generated.<entity>.cs file has most of the guts of your business entities in it. It has all of the properties for each database column. It has Properties for foreign key relationships - an Order will have a Customer property for the customer who owns the order. It will also have collections for entites that have foreign keys to it - an Order will have a collection of OrderDetails. There are static methods to create each object, as well as member methods to create objects - if you have an Order object called order, you can call order.CreateOrderDetail(); to get a new OrderDetail object that is related to the Order. It has a public Save() method that knows what children objects need to be saved - if you have a customer entity, change the name, add an order with two order lines, and call customer.Save() it will update the customer, insert the Order and insert all of the OrderDetail rows. There's more, which I'll cover later in more details.

Lastly, you'll get a project file that includes all of the above files.

Open the solution, build, and you're ready to add your UI to the solution!

Tags: | |

Categories: Development, Software, RCM Technologies