In my application I have about 100 tables like table of customers
CREATE TABLE Customer ( id CHAR(10), name CHAR(20), address CHAR(50) );
Data is edited in WinForm DataGrid . I have table of grid column descriptions
CREATE TABLE InputForm ( Form CHAR(20), FieldName CHAR(20), Caption CHAR(20), Width NUMERIC(2) );
INSERT INTO InputForm VALUES ( 'Customer', 'name', 'Customer Name', 100 );
INSERT INTO InputForm VALUES ( 'Customer', 'address', 'Customer Address', 200 );
My end users can add new fields and input data to those fields at runtime:
ALTER TABLE Customer ADD COLUMN EndUserSpecificField CHARACTER(20);
INSERT INTO InputForm VALUES ( 'Customer', 'EndUserSpecificField', 'Special field value', 10 );
Where to find sample how to create such application in C# ?
I looked into CSLA but havent found any sample aboutnusing dynamic business object properties.
Business object properties are defined statically only, like in Project.cs
private Guid _id;
private string _name = string.Empty;
private SmartDate _started;
etc.
Andrus.
A good example of this can be found in the .NET Framework System.Web.UI.WebControls.WebControl class where an Attributes property is defined to allow users to add their own attributes/properties to a control. This allows the control to be extensible in the way you are describing. In your case, you will have to add the necessary logic to handle selecting and updating the data to/from the DB for these "added" properties just like WebControl uses the Attributes collection during rendering to append the name/value pairs to the HTML output stream.
Something else to consider - use a set of separate child tables in your DB to accomodate this rather than allowing your code to make schema changes. It's just a preferencial thing, but I prefer to have an Attributes table listing the available/defined attributes then another table referencing the parent table (customers), the attribute and specifying the value for that instance. This maps well to your object model as well as you can have a CustomerAttributesCollection object that is responsible for managing these values for your BO.
Hope that helps.
use a set of separate child tables in your DB to accomodate this rather than allowing your code to make schema changes.
Thank you. This may be great idea. However, this requires extra coding for custom attributes.
So I think I put all business object database based-attributes to a list. I think best is to create a single, universal business object which work with any tables.
It would be nice if framework has such a object which can be called from admin menu. This allows framework to edit any table, without additonal encoding. This turns framework into poweful free DBA tool which can be extended by users.
Andrus.
kobruleht:It would be nice if framework has such a object which can be called from admin menu. This allows framework to edit any table, without additonal encoding. This turns framework into poweful free DBA tool which can be extended by users.
Andrus, what you are describing is an application or use of the framework and not something that a framework is intended to do. You can certainly extend the framework to add your own custom classes that can be used to perform DBA tasks, but remember that the classes in a framework should be those that will be reused in multiple applications. If the functionality you are describing is something for a single client application, then that is where the classes should be located.
And, as Andy said, your classes should be modeling behavior not simply mapping data. So, the behavior you are talking about are DBA tasks which is fine, just be sure you want this exposed and that it belongs in a "framework".
kobruleht:use a set of separate child tables in your DB to accomodate this rather than allowing your code to make schema changes.
Thank you. This may be great idea. However, this requires extra coding for custom attributes.
So I think I put all business object database based-attributes to a list. I think best is to create a single, universal business object which work with any tables.
It would be nice if framework has such a object which can be called from admin menu. This allows framework to edit any table, without additonal encoding. This turns framework into poweful free DBA tool which can be extended by users.
Andrus.
Copyright (c) Marimer LLC