views:

246

answers:

3

In the SubSonic docs it lists:

o By default, the Tool generates insert and update code that uses System.Web.HttpContext.Current.User.Identity.Name and System.Threading.Thread.CurrentPrincipal.Identity.Name. Some generated methods may also make use of System.Web classes. If you don’t want to have to add a reference to System.Web in your project, you will have to provide your own templates.

I tried to creat a SubSonic DAL of type C# Class Library. Of course, the files generate, however an error is thrown during build time:

*The type or namespace name 'HttpContext' does not exist ...*

("Is there a separate template available for creating a generic class library DAL that does not include System.Web references?" ? Where : How to modify the existing templates)

Thanks!

A: 

Version 2 has a subdirectory with .aspx files that you can modify to change the template code (you just need to change the path in your app.config file to point to new dir of aspx files).

Version 3 has .tt files that you modify.

Information for how to modify both versions of the templates are on the SubSonic project site.

Jim W
Thanks. I tried adding a reference to System.Web in SubSonic 2.1 Final\src\SubSonic\CodeGeneration\Templates\CS_ClassTemplate.aspx, but I guess I can't find where all the "using..." statements are generated.Secondly, is this the right fix for this - simply adding a ref to System.Web? Will this then allow me to create a stand-alone class library DAL that will properly compile?Thanks.
ElHaix
Look in the design pages of the aspx, you should see a bunch of scripting there. That's where you'll need to do most of your edits. I've never actually removed System.Web from my SubSonic DAL. I use it file (with other changes) in both web and desktop apps without any problems.
Jim W
Hmm, so you don't create a class library for your DAL? I'm guessing you create a WebSite project and just import the DLL to your projects, no?Thanks.
ElHaix
No all of my DALs are individual libraries.
Jim W
+2  A: 

("Is there a separate template available for creating a generic class library DAL that does not include System.Web references?" ? Where : How to modify the existing templates

You need to have a reference to System.Web for SubSonic version 2 or 3 to work. You can just add that to your library project and it'll work.

Adam
+1  A: 

Wow, talk about over-complicating things. I just added a ref to System.Web - got it. For some reason, I thought I'd have to change the .aspx template.

Oops, and thanks.

ElHaix