Skip to main content

Posts

Showing posts from August, 2007

Mono and ProMesh.NET

I follow the Mono Blog aggregator , and Miguel de Icaza mentioned that a user had tested ProMesh.NET on Mono , and it ran without any changes! That in in itself was cool, but when I took a look at ProMesh.Net , it looked like a well designed framework, perhaps comparable to MonoRail . The framework is ORM agnostic, and the biggest weakness might be it's view templates, but they have a great tutorial , so judge for yourself!

My take on Enums in SQL Server

I am a registered user on SQL Server Central , and I read a good article there on " Enums in SQL Server ". I thought that I would quickly present my own humble solution to this problem, although I do not mean to imply that my way is better - you can decide for yourself. First, the problem to be solved is to represent a limited set of choices, where new choices would typically require a developer's intervention to implement the business logic. An example would be a list of task priorities in a to-do list. CREATE TABLE Priorities( ID tinyint not null identity(1,1) PRIMARY KEY, Code char(3) not null unique, Priority varchar(20) not null ) ; INSERT INTO Priorities (Code, Priority) VALUES ('911', 'Emergency') ; INSERT INTO Priorities (Code, Priority) VALUES ('HIG', 'High') ; INSERT INTO Priorities (Code, Priority) VALUES ('NOR', 'Normal') ; INSERT INTO Priorities (Code, Priority) VALUES ('LOW', 'Low') ; IN

Auditing a SQL Server database

I do not believe that I have covered this before, but the Active Record Code Generator can also generate audit records for your database tables. The template that I wrote ( SqlAuditTrigger.vm ) adds records to an AuditChanges table, with a related AuditFields table containing the table and field name. I think that this is a fairly compact solution, but I also added code to the trigger to ignore SA (system administrator) changes. This may not be appropriate for your application, but it is easily removed. I also have a "TODO" item to detect related lookup tables (really ENUMs) and translate IDs to Names, so that changes to the FavoriteColor_ID field would look at the FavoriteColor table, and instead of recording FavoriteColor_ID changed from 2 to 5, it would say changed from "Ruby Red" to "Passionate Purple". The reason that I did not actually implement it is that I do not have enough information. My code generation schema does not list all of the f

I love Bouncy Castle!

Today, I needed to send some private data to another company, and I could not get FTP with SSL to authenticate over our firewall, so I had to sent an encrypted file over FTP. The other company has a GPG public key, so I looked around for a bit on the web (yes, I googled c# gpg encrypt open source) and found a message that mentioned Bouncy Castle on the 4th or 5th page (why was it so far down the list???). I then googled Bouncy Castle to finally find that they have a wonderful c# implementation of GPG encryption (and many others), and their test code includes an example that reads a file and writes an encrypted file. This made integration VERY simple. I did move their test folder into their test project, so I would not be deploying all of the test code to production.

What happened to VS2005 Data Pro Power Tools?

I was reading a blog on MSDN, with a link to some cool Power Toys for Visual Studio 2005 Team Edition for Database Professionals. So today, I had some time to install the VS2005 TE Service Release 1 so I could grab the power toys, but the microsoft link is dead! The developer went on a vacation (literally), so it might be a while until this gets fixed. Oh, by the way, O’Reilly Hacking Visual Studio mentions a cool documentation tool called GhostDoc . It looks slick! Update: Here is the link , thanks to Michael!

NHibernate hbm xml template

Friday, I added an NHibernate mapping.hbm.xml template. I mainly wanted to show that the code generator can be used for other purposes than just Castle ActiveRecord, and NHibernate is an easy target. Jim R. has requested that I add HasMany (aka ManyToOne) mapping properties and attributes. I think this is going to push me to refactor the schema extraction code. Some of my future goals for the application are: 1. Full Model Generation (list of children, whether directly or indirectly through a many-to-many table) 2. User controllable plural-to-singular mapping. 3. Multi-database, using the Database Provider Factory. 4. Refactor code generation into a library (as I do with all projects) 5. Command-line code generation (supply at least a template and a list of tables) 6. Templates for other ORM tools (pure NHibernate, Rocky Lhotka's CSLA Business Objects, etc.)

Improved Model generation in Code Generator

I have improved the Inequality test in the model template, as requested by JimR . This was another case where it worked well for me, only because I followed the convention that primary keys are named ID, and foreign keys are named SingularOfTable_ID. I know that I should really push the Inequality test into the template, but for now, I have corrected it in the DbFieldInfo class.

Features of the Code Generator

I just updated my code generator to optionally generate validation attributes. This simple change includes App.config file entries for all check boxes, and a new checkbox for "Validation" - aka validation attibute generation. While I was making this change, I realized that I really need to pass a CodeGenerationContext object to the DbTable, DbField and ModelGenerator classes. The requester can populate the context, and pass it to the code generator. Anyway, enough about the code, let's talk about the templates. I made a simple template this weekend to generate a DataGridView column array, suitable for databinding. I'm sure my new template will need some tweaks to handle Foreign Keys better (it currently just displays them as TextBox). Let's look at a template. ##FILENAME:PR_${table.GetClassName()}_Insert.sql ## ## Generate a SQL stored procedure to insert a record into the ## specified table and return the newly created primary key ## ## FUTURE: The generat

ActiveRecord Code Generator

Thanks to some recent interest in the community, I have made a few more changes to ActiveRecord Code Generator . First, I added a browse button and a dialog, using some code supplied by Jim R . I don't care for the folder browser dialog, but it is built in to .Net 2, so I use it. Second, I fixed a few bugs that crop up when a table does not match my arbitrary table and field naming scheme. This project was written quickly as a pre-requisite to a large project, and it shows, but it is steadily improving. Evening Update: I added a POCO (Plain Old C# Object) template as a starting point for an NHibernate cs and xbm template set.