tags:

views:

172

answers:

2

I'm using SubSonic 2.2 for my DAL. To match the requirement, I need to customize some of classes which generated by SubSonic. For sample:

public partial class Category : ActiveRecord, IActiveRecord, IOtherInterface

Could you please give me some clues. Where I can modify the generated template? Thanks!

+1  A: 

(edit: see runxc1's post for better answer)

You can modify the templates used to generate the class files to add in your other interface. You can't add an interface to the partial classes. The only trick is that this will add it to all generated classes. You can also just go into your automatically generated classes and add your interface manually after you generate the class files.

SubSonic 2.2 templates are a bit tricker to work with than the 3.0 templates, but it's still really easy to modify the templates.

See below links for info:

Your options:

  1. Modify templates used for generation to add in your interface (all classes), or
  2. Modify templates used for generation to add in if/switches to only add interfaces to certain classes that match specific names, etc., or
  3. Edit generated classes to add in your interface (must redo edits after each auto-generation)

After you modified those aspx files. Then you'll just need to update your .config file of your DAL to specify the new path to your customized aspx files and regen as usual.

Jim W
Thanks so much, Jim. Your sharing is very useful to me. But I still have a question. I found no Template folder after installed SubSonic 2.2. But I see another one in SS 2.1 folder..\SubSonic 2.1 Final\src\SubSonic\CodeGeneration\TemplatesIs it still OK if I use the template from SS-2.1 and generate classes using SS-2.2?
cha
I think so. I originally modified my templates when I used 2.1 and afterwards, I upgraded to 2.2 and I didn't change my templates. There's no backwards compatibility issues (none that I know of) between 2.1 and 2.2.
Jim W
Thanks Jim, I've tried with the Template from SS2.1 as mentioned and modified a little bit, everything should be fine now.
cha
+1  A: 

Jim is incorrect you can add an Interface via the partial class. I keep one folder with all of the Generated Files and another one with the Altered class files and I am adding an interface to the altered class files and it works just fine.

   public partial class ContainerSearch : IContainerSearch
{
}

above is an example from my code I am using now

runxc1 Bret Ferrier
Ah, thanks. I didn't know that. I thought you had to define the interfaces on the other class.
Jim W
I've tried both of suggestions, they work well. Since I have to customize the Get/Set method of the class object (i.e class Category), it required me to edit the template a bit. Thanks all for your support.
cha