In my previous article, I explained how by modifying Marc Andre Cournoyer's generator, we made it generate Ajax based, scaffolding code for Castle MonoRail. In the meantime, my colleague Gabi Munteanu, managed to put together a Visual Studio 2005 addin, exactly for this purpose.
1. Generate the model
Let's start from an generated ActiveRecord class called Project we had the last time, generating the ajax scaffolding code needed for the project:
obtaining:
using Castle.ActiveRecord;
namespace Models
{
///
/// An instance of this class represents a Project.
///
[ActiveRecord]
public class Project : ActiveRecordValidationBase
#region Fields
private int _id;
private string _name;
private string _description;
#endregion
#region Persistent properties
[PrimaryKey]
public int Id {
get { return _id; }
set { _id = value; }
}
[Property]
public string Name {
get { return _name; }
set { _name = value; }
}
[Property]
public string Description {
get { return _description; }
set { _description = value; }
}
#endregion
}
}
Using the ActiveRecordStarter.CreateSchema we also create the corresponding database table.
2. Generate the scaffold
then
Unfortunetely, we'll still have to manually include the files in the project (still working on this):
3. Final adjustments
In order to make it work we need some adjustments to our Project class:
using System.Collections;
using Castle.ActiveRecord;
using NHibernate.Expression;
namespace Models
{
///
/// An instance of this class represents a Project.
///
[ActiveRecord]
public class Project : ActiveRecordValidationBase {
#region Fields
private int _id;
private string _name;
private string _description;
#endregion
internal static IList FindAll()
{
return FindAll(typeof(Project));
}
internal static IList FindAll(string property)
{
return property.Equals("") ? FindAll(typeof(Project), new Order[1] { Order.Desc("Id") }) : FindAll(typeof(Project), new Order[1] { Order.Asc(property) });
}
internal static Project Find(int id)
{
return FindByPrimaryKey(typeof(Project), id) as Project;
}
#region Persistent properties
[PrimaryKey]
public int Id {
get { return _id; }
set { _id = value; }
}
[Property]
public string Name {
get { return _name; }
set { _name = value; }
}
[Property]
public string Description {
get { return _description; }
set { _description = value; }
}
#endregion
}
}
Now we see the result:
Conclusion
The project is till in early stages, but it can still generate very good code and save a lot of time needed to generate the same all CRUD code, needed in any application.
6 comments:
Dane,
Ma omori nene. -- Am crezut ca esti Roman.
I love it and can't wait to try it out tonight.
Ciao,
Pai sunt roman, si stau si-n Romania (Timisoara). Numai ca publicul de engleza e mai larg. Voi veni curand cu o versiune mai noua, sper sa il integram in proiectul Castle la Contrib.
Merci,
Dan Bunea
GREAT CODE GREAT UTIL !!!
salut, linkul pentru add-in nu mai e valabil..
ai vreunul mai nou?
Dan
Il caut si-l urc din nou. Da-mi un mail pe dan.bunea pe gmail, te rog, sa nu uit.
Merci,
Hello, the VS2005 addin is not available, the website seems to be down! Can you please, please, make the addin available again?
Best regards,
Rui Isidro
Post a Comment