Design a lookup table
"Lookup" Table Schema:
- ID - int primary key
- Name - varchar(50)
- Type - Discreminator Column
Generate ActiveRecord classes
[ActiveRecord("List_Lookups",
DiscriminatorColumn = "Type",
DiscriminatorType = "String",
DiscriminatorValue = "NA")]
public class Lookup: ActiveRecordBase
{
.... some code ...
}
sub-class code like this
[ActiveRecord(DiscriminatorValue = "PTL")]Testing
public class ProjectTypeList: Lookup
{
}
Lucky that I start with this:
ProjectTypeList.DeleteAll();Which cause all the records in the Lookup table deleted. WEIRD !
It suppose to delete all records in Lookup table with column Type = "PTL"
Okay, I keep testing with FindAll() method and the result was not satisfied. I start lookup for the solution in the forum finally I got the answer from Hammett's replied.
The answer is:
"Implement our own DeleteAll(), FindAll() and other method by in the derived classes."I hope I won't waste my time next time I tried to deal with this scenario.
using Castle.ActiveRecord;
namespace PID.Net.Models
{
[ActiveRecord(DiscriminatorValue = "PTL")]
public class ProjectTypeList: Lookup
{
public new static void DeleteAll()
{
DeleteAll(typeof (ProjectTypeList));
}
public new static ProjectTypeList[] FindAll()
{
return (ProjectTypeList[]) FindAll(typeof (ProjectTypeList));
}
}
}